-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeygen.c
More file actions
36 lines (27 loc) · 700 Bytes
/
keygen.c
File metadata and controls
36 lines (27 loc) · 700 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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
char *oKey = argv[1]; // original key
printf("Text: ");
char plaintext[512];
fgets(plaintext, 512, stdin);
printf("oKey: %s\n", oKey);
int oKeyLen = strlen(oKey); // length of key
int pLen = strlen(plaintext);
char *rKey = calloc(pLen, sizeof(char)); // repeat key
int i = 0; // track position in plaintext
int j = 0; // track position in oKey
while (i < pLen)
{
if (j > oKeyLen)
j = i % oKeyLen;
rKey[i] = oKey[j];
i++;
j++;
}
printf("rKey: %s\n", rKey);
return 0;
}