document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2.  
  3. enum CHOICE { ENCRYPT = 1, DEENCRYPT };
  4.  
  5. void GetString( char* );
  6. void SelectMenu( int* );
  7. void GetChangeAmount( int* );
  8. void ChangeString( char*, const int, const int );
  9. void PrintResult( char*, const int );
  10.  
  11. int main( void )
  12. {
  13.     char string[64];
  14.     int choice, amount;
  15.  
  16.     GetString(string);
  17.     SelectMenu(&choice);
  18.     GetChangeAmount(&amount);
  19.  
  20.     ChangeString(string, choice, amount);
  21.     PrintResult(string, choice);
  22.  
  23.     return 0;
  24. }
  25.  
  26. void GetString( char *str )
  27. {
  28.     printf("문자열 입력 : ");
  29.     scanf("%s", str);
  30. }
  31.  
  32. void SelectMenu( int *cho )
  33. {
  34.     printf("실행(1-암호화, 2-복호화) : ");
  35.     scanf("%d", cho);
  36. }
  37.  
  38. void GetChangeAmount( int *amo )
  39. {
  40.     printf("암호키(복호키) 입력 : ");
  41.     scanf("%d", amo);
  42. }
  43.  
  44. void ChangeString( char *str, const int cho, const int amo )
  45. {
  46.     int i;
  47.  
  48.     switch( cho )
  49.     {
  50.     case ENCRYPT:
  51.         for( i = 0; str[i] != \'\\0\'; i++ )
  52.         {
  53.             if( str[i]+amo > \'z\' )
  54.             {
  55.                 int less = str[i]-\'z\';
  56.                
  57.                 str[i] = \'a\';
  58.                 str[i]+=less;
  59.             }
  60.             else
  61.                 str[i]+=amo;
  62.         }
  63.         break;
  64.     case DEENCRYPT:
  65.         for( i = 0; str[i] != \'\\0\'; i++ )
  66.         {
  67.             if( str[i]-amo < \'a\' )
  68.             {
  69.                 int plus = \'a\'-str[i];
  70.  
  71.                 str[i] = \'z\';
  72.                 str[i]-=plus;
  73.             }
  74.             else
  75.                 str[i]-=amo;
  76.         }
  77.     }
  78. }
  79.  
  80. void PrintResult( char *str, const int cho )
  81. {
  82.     switch( cho )
  83.     {
  84.     case ENCRYPT:
  85.         printf("암호문 : ");
  86.         break;
  87.     case DEENCRYPT:
  88.         printf("복호문 : ");
  89.     }
  90.     puts(str);
  91. }
');