Wednesday, March 14, 2012

Enforcing Privacy with Cryptography

Simple crypter/decrypter
(I means really simple)

Reads four digit integer.Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth.The decrypter works reversely.
/*
   title: EnforcingPrivacyWithCryptography
   author: aeriqusyairi
   date: dec30 2011
*/
#include<stdio.h>
#include<stdlib.h>

int main(){
    int integer=0,explode=0,a=0,b=0,c=0,d=0,i=1,swap=0,option=0;
    
    printf("Input the 4 digit integer: ");
    scanf("%d",&integer);
    
    printf("Select an option...\n1.Encrypt\n2.Decrypt\nOption: ");
    scanf("%d", &option);
    
    while(i <= 4){
       explode = integer % 10;
       integer /= 10;
       
       if(i == 1)
          d = explode;     
       else if(i == 2) 
          c = explode; 
       else if(i == 3) 
          b = explode; 
       else if(i == 4) 
          a = explode;  
          
       i++;        
    }
    
    if(option == 1){
       a = (a + 7) % 10;
       b = (b + 7) % 10;
       c = (c + 7) % 10;
       d = (d + 7) % 10;
    }else if(option == 2){
       a = (a + 3) % 10;
       b = (b + 3) % 10;
       c = (c + 3) % 10;
       d = (d + 3) % 10;   
    }

    printf("%d%d%d%d\n",c,d,a,b);

    system("pause");
    return 0;   
}

No comments:

Post a Comment