-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvigenere_encrypt.c
More file actions
44 lines (30 loc) · 897 Bytes
/
vigenere_encrypt.c
File metadata and controls
44 lines (30 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Author - Michael Ibeh
// License - Apache Version 2.0
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "CipherSolve.h"
void vigenere_encrypt(void){
char buffer[1024], key[1024], plaintext[1024], hold, *cipher;
int message_len, keylen, i = 0;
// Processing the key
printf("What is the key?\n");
scanf("%s", buffer);
strcpy(key, buffer);
keylen = strlen(key);
// Process Plain Text
printf("What is the message you would like encrypted?\n");
scanf("%s", buffer);
strcpy(plaintext, buffer);
message_len = strlen(plaintext);
printf("\nCiphertext:\n\n");
for(i = 0;i < message_len; i++)
plaintext[i] = tolower(plaintext[i]);
plaintext[i] = ( ( ( (plaintext[i] - 'a') + (key[i % keylen] - 'a') ) % 26) + 'a');
for(i = 0; i < message_len; i++){
printf("%c", plaintext[i]);
if( ((i + 1) % 80) == 0 )
printf("\n");
}
printf("\n");
}