Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
const cypher_index;
char cypherText[] = "LMU XOASR JCZIK VZN EODTUP ZHUC LMU GFWY PZBQ";
char plainText[sizeof(cypherText)];

char cypher[] = {'I', 'G', 'R', 'M', 'J', 'A', 'L', 'V', 'W', 'B', 'N', 'T', 'H', 'X', 'U', 'D', 'S', 'K', 'C', 'P', 'E', 'F', 'Z', 
                 'Q', 'Y', 'O', ' ', '\n', '\0' };

// index returns an integer that can be used to find the plain text 
// equivalent of a cypher text letter.
int index(char letter) {
   switch (letter) 
   {
      case (' '): return 26;
      case ('\n'): return 27;
      case ('\0'): return 28;
      default: return (int) (letter - 'A');
   }
}

void setup() {
   // initialize serial communication at 9600 bits per second:
   Serial.begin(9600);

   // Fill the plainText array with null characters so that print
   // stops
   for (int i = 0; i < sizeof(plainText); i ++) {
      plainText[i] = '\0';
   }


What I have tried:

I tried to make loop that will examine each character in cypherText and convert the character to its plain text equivalent. The function index returns an integer that you can use to find the plain text letter from the array cypher. it did not work
Posted
Updated 14-Dec-17 14:11pm
v2

1 solution

C#
// inside the loop goes:

plainText[i] = cypher[index(cypherText[i])];

// explanation for the first letter in cypherText:
// cypherText[0] = 'L'
// index('L') returns 11
// cypher[11] = 'T'
// plainTest[0] = 'T'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900