Question

How can we know when the code implementation of a cryptographic algorithm is correct to use?...

How can we know when the code implementation of a cryptographic algorithm is correct to use? Justify your answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Cryptiographic: when the program converts the plan text to cipher text and cipher text to the plan text.

Then we can say that that code is correctly implemented the cryptographic. The following example will explain the cryptographic encryption and decryption.

Encryption: converts the plain text to cipher text

Decryption: Coneverts the cipher text to plain text

C++ Source Code:

#include<iostream>

using namespace std;

int main()
{
char data[100], ch;
int i, cryptokey;
char choice[1];
do
{
cout<<"\nEnter your choice \n E->Encryption\nD->Decryption\nQ->Quit\n";
cin>>choice;
if(choice[0]=='e' || choice[0]=='E')
{
cout << "Enter a message to encrypt: ";
cin>>data;
cout << "Enter key: ";
cin >> cryptokey;
  
for(i = 0; data[i] != '\0'; ++i){
ch = data[i];
  
if(ch >= 'a' && ch <= 'z'){
ch = ch + cryptokey;
  
if(ch > 'z'){
ch = ch - 'z' + 'a' - 1;
}
  
data[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + cryptokey;
  
if(ch > 'Z'){
ch = ch - 'Z' + 'A' - 1;
}
  
data[i] = ch;
}
}
  
cout << "Encrypted message: " << data;
}
else if(choice[0]=='d' || choice[0]=='D')
{
cout << "Enter a message to decrypt: ";
cin>>data;
cout << "Enter key: ";
cin >> cryptokey;
  
for(i = 0; data[i] != '\0'; ++i){
ch = data[i];
  
if(ch >= 'a' && ch <= 'z'){
ch = ch - cryptokey;
  
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}
  
data[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - cryptokey;
  
if(ch > 'a'){
ch = ch + 'Z' - 'A' + 1;
}
  
data[i] = ch;
}
}
  
cout << "Decrypted message: " << data;
}
}while(choice[0]!='Q');
  
  
return 0;
}

Output:

Enter your choice

E->Encryption

D->Decryption

Q->Quit

E

Enter a message to encrypt: hemanth

Enter key: 5

Encrypted message: mjrfsym

Enter your choice

E->Encryption

D->Decryption

Q->Quit

D

Enter a message to decrypt: mjrfsym

Enter key: 5

Decrypted message: hemanth

Enter your choice

E->Encryption

D->Decryption

Q->Quit

Q

Add a comment
Know the answer?
Add Answer to:
How can we know when the code implementation of a cryptographic algorithm is correct to use?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT