encripting 4-digit integer?

• 12-24-2003
o0o
encripting 4-digit integer?
Code:

``` #include<iostream> #include<conio.h> using std::cout; using std::cin; using std::endl; int main() {     // declare variables         int num,digit1,digit2,digit3,digit4,sum1,sum2,sum3,sum4;         // initialize variables         sum1=0,sum2=0,sum3=0,sum4=0;         cout<<"\nEnter a 4 digit integer:\t";     cin>>num;         // separate the integers         digit1=num%10;         num/=10;     digit2=num%10;         num/=10;     digit3=num%10;         num/=10;     digit4=num%10;         // replace digits         sum1=(digit1+7)%10;     sum2=(digit2+7)%10;     sum3=(digit3+7)%10;     sum4=(digit4+7)%10;     // swap digits         cout<<"Encripted integer\t\t";         cout<<sum2<<sum1<<sum4<<sum3;     getch(); }```
Is this correct encription?I was trying to swap the first digit with the third one and second with the fourth one, ofcourse after replacing each digit with its sum plus 7 % 10.
• 12-24-2003
joshdick
As an important side note, I suggest reading up on arrays and vectors so that you don't have to declare four similar, sequential variables like that.

As for your encryption scheme, it appears to me that it would work. By adding seven, you've just got a simple caesar shift there. Then you mix up the digits.

I think the real test will now be if you can decrypt those messages. Swap the digits back correctly, and shift back to the correct position. That ought to do it. Good luck.
• 12-25-2003
o0o
decripting 4-digit integer/
Code:

```#include<iostream> #include<conio.h> using std::cout; using std::cin; using std::endl; int main() {     // declare variables         int num,digit1,digit2,digit3,digit4,dcript1,dcript2,dcript3,dcript4;         // initialize variables         dcript1=0,dcript2=0,dcript3=0,dcript4=0;         // read integer         cout<<"\nEnter the integer to be decripted:\t";     cin>>num;         // separate integers         digit1=num%10;     num/=10;     digit2=num%10;     num/=10;     digit3=num%10;     num/=10;     digit4=num%10;     num/=10;         // print decripted digit         if((digit1<7||digit2<7)||(digit3<7||digit4<7))     {         dcript1=(10+digit1)-7;         dcript2=(10+digit2)-7;         dcript3=(10+digit3)-7;         dcript4=(10+digit4)-7;                 cout<<"\nDecripted 4-digit integer:\t\t";         cout<<dcript2<<dcript1<<dcript4<<dcript3;     }     else         dcript1=(digit1-7)%10;         dcript2=(digit2-7)%10;         dcript3=(digit3-7)%10;         dcript4=(digit4-7)%10;           getch(); }```
See the attachment , the only prob is it outputs last integer thrice.
• 12-25-2003
o0o
sorryculdn't attach the file
sorry couldn't attach the file
• 12-25-2003
WDT
Honestly dude XMAS?? There no rest for the wicked??
• 12-25-2003
quzah
Code:

```else         dcript1=(digit1-7)%10;         dcript2=(digit2-7)%10;         dcript3=(digit3-7)%10;         dcript4=(digit4-7)%10;```
Did you mean to have a pair of braces around that? Otherwise the last three always happen.

Quzah.