-
Encrypt a message
about 9 years ago
-
about 9 years ago
hi there,
This might help you to encrypt your message :)
#include <stdio.h> #include <stdlib.h> #include <string.h> #define LIM 1000 void hexToDec(int a[],char *key, int n) { int i; int keyLen; keyLen = strlen(key); for ( i = 0; i < keyLen; i++) { if( key[i] > 64 && key[i] < 71) { a[i] = key[i] - 55; } else { a[i] = key[i]-48; } } if ( i < n) { int value = 0; while( i != n) { a[i] = value; value++; i++; if ( value == 16) { value = 0; } } } return; } void fun(char *encryptedMessage, char *message, char *encryptionKey) { int msgLen = strlen(message); int arr[msgLen]; int i; hexToDec(arr,encryptionKey,msgLen); // used to fill the array arr to repective decimal value for ( i = 0; i < msgLen; i++) { encryptedMessage[i] = message[i] + arr[i]; } encryptedMessage[i] = '\n'; return; } int main() { char message[LIM]; char encryptionKey[LIM]; char encryptedMessage[] = ""; printf("Enter the message : "); scanf("%[^\n]%*c",message); printf("Enter the encryption key : "); scanf("%[^\n]%*c",encryptionKey); printf("Message : %s\n",message); fun(encryptedMessage,message,encryptionKey); printf("Encrypted Message : %s\n",encryptedMessage); return 0; }
-
1 Answer(s)