How do I create an algorithm for encryption that will let the user enter a strin
ID: 3666001 • Letter: H
Question
How do I create an algorithm for encryption that will let the user enter a string that will be scrambled by alternating characters from the beginning and end of an array. And the minimum functions I can use are : 1. Int length (const char input [ ]; 2. Void encrypt(const char original[ ], char encrypted[ ] ); Also the libraries I may use is iostream How do I create an algorithm for encryption that will let the user enter a string that will be scrambled by alternating characters from the beginning and end of an array. And the minimum functions I can use are : 1. Int length (const char input [ ]; 2. Void encrypt(const char original[ ], char encrypted[ ] ); Also the libraries I may use is iostream 1. Int length (const char input [ ]; 2. Void encrypt(const char original[ ], char encrypted[ ] ); Also the libraries I may use is iostreamExplanation / Answer
I will give encryption using XOR encryption technique...
Here algorigthm code with comments .....
//length method
int length(const char input[]){
//declare length variable
int length=0;
//looping through array
for(int i=0;i<input.size();i++){
if(input[i] !== ''){
length++;
}
}
return length;
}
------------------------------------------------------------------------------------
//encryption method
void encrypt(const char original[], char encrypted[]){
//we will encrypt using some character as key .. i take 'm'
char key = 'm';
//printing input before encryption
for(int i=0;i<original.size();i++)
{
cout<<original[i]<<" ";
}
//looping through input array and encrypt it...
for(int i=0;i<original.size();i++)
{
encrypted[i] = original[i] ^ key;
}
//printng encrypted data
for(int i=0;i<original.size();i++)
{
cout<<encrypted[i]<<" ";
}
}
*************************** HERE IS YOUR ANOTHER ALGORITHM APPROACH .. SCRAMBLING CHARACTERS FROM BEGINNING AND END OF AN ARRAY ******************************************************
//encryption method
void encrypt(const char original[], char encrypted[]){
//storing characters .. changing positions
//getting length
int length = length(original);
//changing positions and storing into encrypted array
for(int i=0;i<=length;i++){
//storing alternative chars into array
encrypted[i] = original[length-1];
if(i != length){
encrypted[length-1] = original[i];
}
//decrementing length variable
length--;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.