http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_Crypto&no=5 [º¹»ç]
#include <stdio.h>
#include <ctype.h>
void Encrypt(char *ptr)
{
char a;
int key;
printf(" Key : ");
scanf("%d",&key);
printf("\n!!!Encrypting Success!!!\n\n");
while (*ptr)
{
if (islower(*ptr))
{
a=(*ptr)+key;
if((*ptr)+key > 'z')
a=((*ptr)+key) - 26;
printf("%c", a);
}
else if (isupper(*ptr))
{
a=(*ptr)+key;
if((*ptr)+key > 'Z')
a=((*ptr)+key) - 26;
printf("%c", a);
}
else
printf("%c", *ptr);
ptr++;
}
printf("\n");
};
void Decode(char *ptr)
{
int key;
char a;
printf(" Key : ");
scanf("%d",&key);
printf("\n!!!Decoding Success!!!\n\n");
while (*ptr)
{
if (islower(*ptr))
{
a=(*ptr)-key;
if((*ptr)-key < 'a')
a=((*ptr)-key) + 26;
printf("%c", a);
}
else if (isupper(*ptr))
{
a=(*ptr)-key;
if((*ptr)-key < 'A')
a=((*ptr)-key) + 26;
printf("%c", a);
}
else
printf("%c", *ptr);
ptr++;
}
printf("\n");
};
// brute-force attack
void BruteForceAttack(char *ptr)
{
char a[300]="";
int i;
int key;
for(key=1 ; key<26 ;)
{
for(i=0; i<26 ;)
{
while (*ptr)
{
if (islower(*ptr))
{
a[i]=(*ptr)-key;
if((*ptr)-key < 'a')
a[i]=((*ptr)-key) + 26;
printf("%c", a[i]);
key++;
i++;
}
else if (isupper(*ptr))
{
a[i]=(*ptr)-key;
if((*ptr)-key < 'A')
a[i]=((*ptr)-key) + 26;
printf("%c", a[i]);
key++;
i++;
}
else
printf("%c", *ptr);
ptr++;
}
}
}
};
void main(void)
{
char buffer[200];
char *ptr;
int choose;
while (1)
{
printf("\n********************************************************");
printf("\n [1] Encrypt\n [2] Decode\n [3] Brute-Force Attack\n [4] Escape : \n:::Please Choose Menu Number : ");
scanf("%d", &choose);
fflush(stdin);
if(choose == 1)
{
printf("\n!!!Caesar Cipher, You chosen Encrypt!!! \n Input Sentence : ");
gets(buffer);
ptr=buffer;
Encrypt(ptr);
}
else if(choose == 2)
{
printf("\n!!!Caesar Cipher, You chosen Decode!!!\n Input Cipher : ");
gets(buffer);
ptr=buffer;
Decode(ptr);
}
else if(choose == 3)
{
printf("\n!!!Caesar Cipher, You chosen Brute-Force Attack for Decode!!!\n Input Cipher : ");
gets(buffer);
ptr=buffer;
BruteForceAttack(ptr);
}
else if(choose == 4)
break;
else
printf("\nSorry, I couldn't do so. Check Menu Number..\n");
}
}
// ¾ÏÈ£È, º¹È£È´Â Àß µË´Ï´Ù..
//±Ùµ¥ Àü»çÀû°ø°Ý(¸Þ´º3¹ø) ½ÇÇà½Ã ÀÌ»óÇÑ °á°ú°ªÀÌ ³ª¿À³×¿ä..
//°è¼Ó ¸·Çô¼ ÁøÀüÀÌ ¾ÈµÇ ¤Ð¤Ð Å°°ª1¹øºÎÅÍ 25¹ø±îÁö ´ëÀÔÇÑ °ªÀÌ Ãâ·ÂµÇµµ·Ï
//ÇÏ°í½ÍÀºµ¥ ¾ÈµÇ³×¿µ ¤Ð ÇÏ·çÁ¾ÀÏ Çß´õ´Ï ¸Ó¸®°¡ ¸ÛÇØÁ®¼ »ý°¢µµ ¾È³ª°í..
//±ÍÂú°ÚÁö¸¸ ÀÚºñÁ»ºÎŹµå¸³´Ï´Ù
//for¹®À¸·Î 25°³ÀÇ Çص¶¹®À» Ãâ·ÂÇÒ¶ó¸é¸¦ ÇÏ·Á¸é ´ë¼Ò¹®ÀÚ ±¸º°Çؼ °ª ´õÇØÁÖ´Â ÇÔ¼ö¸¦ µû·Î ¸¸µé¾î¼
//»ç¿ëÇØ¾ß ÇÒ±î¿ä? ÇïÇÁ¤»
* ¸Û¸Û´Ô¿¡ ÀÇÇؼ °Ô½Ã¹° À̵¿µÇ¾ú½À´Ï´Ù (2010-11-28 12:38) |
Hit : 6283 Date : 2010/10/13 11:16
|