Guest User

Untitled

a guest
Dec 14th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. enter code here
  2. char cypherText[] = "LMU XOASR JCZIK VZN EODTUP ZHUC LMU GFWY PZBQ";
  3. char plainText[sizeof(cypherText)];
  4.  
  5. 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',
  6. 'Q', 'Y', 'O', ' ', 'n', '' };
  7.  
  8. // index returns an integer that can be used to find the plain text
  9. // equivalent of a cypher text letter.
  10. int index(char letter) {
  11. switch (letter)
  12. {
  13. case (' '): return 26;
  14. case ('n'): return 27;
  15. case (''): return 28;
  16. default: return (int) (letter - 'A');
  17. }
  18. }
  19.  
  20. void setup() {
  21. // initialize serial communication at 9600 bits per second:
  22. Serial.begin(9600);
  23.  
  24. // Fill the plainText array with null characters so that print
  25. // stops
  26. for (int i = 0; i < sizeof(plainText); i ++) {
  27. plainText[i] = '';
  28. }
  29.  
  30. // Insert your code to decypher the message
  31.  
  32. // Print the plainText
  33. Serial.print(plainText);
  34. }
  35.  
  36. void loop() {
  37.  
  38. std::string encrypted_text;
  39. for (size_t i = 0; i < sizeof(cypherText); ++i)
  40. {
  41. const char c = cypherText[i];
  42. const cypher_index = index(c);
  43. encrypted_text += cypher[cypher_index];
  44. }
Add Comment
Please, Sign In to add comment