Latest News

Simple Caesar and Rot Cipher

Sunday, 19 September 2010 , Posted by genesisdatabase at 11:28

[code]
/*
* url: http://genesisdatabase.wordpress.com
* email: genesisdatabase@gmail.com
*
* This source code is free to be used by any programmers
* Source code converts all uppercase to lowercase during decryption
* Supports command line usage, use text as argument eg. crack.exe "abcdef"
*/

#include <stdio.h>
#include <string.h>
//#include <stdlib.h> /*include if using system()*/

void DecryptCaesar(char *Encrypted)
{
char i;
int j;

Encrypted = strlwr(Encrypted); /*supports only lowercase*/
//system("REM"); /*use this to copy paste in windows*/


printf(" Caesar Ciphernn");
for(i = 0 ; i < 27 ; i++)
{
printf(" [+%d]t", i);
for(j = 0 ; j < (signed)strlen(Encrypted) ; j++)
{
if(Encrypted[j] == ' ')
printf(""); /*replace "" with " " if you prefer to preserve spacing*/
else if(Encrypted[j] < 'a' || Encrypted[j] > 'z')
printf("%c", Encrypted[j]); /*preserved non-alphabets*/
else if(Encrypted[j] + i > 'z')
printf("%c", Encrypted[j] + i - 26);
else
printf("%c", Encrypted[j] + i);
}

if(i == 13)
printf(" (ROT)");

printf("n");
if(i == 25)
{
printf(" ");
for(j = 0 ; j < (signed)strlen(Encrypted) + 8 ; j++)
printf("-");

printf("n");
}

}
printf("n");
}
int main(int argc, char **argv)
{
char string[64 +1] = {'\0'};

if(argc == 2)
{
strncpy(string, argv[1], 64);
printf("n");
DecryptCaesar(string);
return 0;
}

for( ; ; )
{
printf("n Enter a text to encrypt/decrypt (EXIT to quit): ");

fflush(stdin); /*windows*/
//fpurge(stdin); /*linux*/

scanf("%64[^n]", string);

if(string[0] == 'E' && string[1] == 'X' && string[2] == 'I' && string[3] == 'T' && string[4] == '\0')
break;


printf("nn");
DecryptCaesar(string);
}

printf("n Thanks for using...n");
return 0;
}
[/code]

Currently have 0 comments:

Leave a Reply

Post a Comment