Created
October 13, 2011 20:34
-
-
Save ipa/1285445 to your computer and use it in GitHub Desktop.
vignere encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define OFFSET 97 | |
int main(int argc, char* argv[]) | |
{ | |
char* klartext; | |
char* geheimtext; | |
char* schluessel; | |
int counter; | |
int laenge; | |
if(argc != 3) | |
{ | |
printf("Falsche Parameter\n"); | |
return EXIT_FAILURE; | |
} | |
klartext = (char*)strdup(argv[1]); | |
geheimtext = (char*)malloc(sizeof(klartext)); | |
schluessel = (char*)strdup(argv[2]); | |
laenge = strlen(klartext); | |
for(counter = 0; counter < laenge; counter++) | |
{ | |
char c = klartext[counter]; | |
int offset = (int)schluessel[counter % strlen(schluessel)] - OFFSET; | |
c = (char)((((((int)c) - OFFSET) + offset) % 26) + OFFSET); | |
geheimtext[counter] = c; | |
} | |
printf("Klartext: %s \n", klartext); | |
printf("Geheimtext: %s \n", geheimtext); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment