Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. int inByte = 0; // serial input and output character
  2. void setup() {
  3. // put your setup code here, to run once:
  4. Serial.begin(9600); // initialize the serial port at 9600 baud
  5. while (!Serial) {
  6. ; // wait for serial port to connect
  7. } // wait for serial port to connect
  8. establishContact(); // wait for incoming data
  9. } /* setup */
  10. void loop() {
  11. // put your main code here, to run repeatedly:
  12. // This is the Rotate 13 encryption algorithm
  13. // If you run the algorithm twice, you get back the original message
  14. // Example: ABC -> NOP -> ABC
  15. if (Serial.available() > 0) // if you have data input
  16. {
  17. inByte = Serial.read(); // read one byte of input
  18. // A to M get converted to N to Z
  19. if (inByte >= 'A' && inByte <= 'M')
  20. {
  21. inByte += 13;
  22. } /* if upper case A-M */
  23. // N to Z get converted to A to M
  24. else if (inByte >= 'N' && inByte <= 'Z')
  25. {
  26. inByte -= 13;
  27. } /* if upper case N-Z */
  28. // Lower case a to m get converted to n to z
  29. else if (inByte >= 'a' && inByte <= 'm')
  30. {
  31. inByte += 13;
  32. } /* if lower case a-m */
  33. // Lower case n to z get converted to a to m
  34. else if (inByte >= 'n' && inByte <= 'z')
  35. {
  36. inByte -= 13;
  37. } /* if lower case n-z */
  38. Serial.write(inByte); // write the encrypted character back
  39. } // if Serial.available() > 0
  40. } /* loop */
  41. void establishContact()
  42. {
  43. // write 'A' repeatedly until you receive data from the host
  44. while (Serial.available() <= 0)
  45. {
  46. Serial.print('A'); // write 'A' to the host
  47. delay(1000); // this delay is optional
  48. } // while Serial.available() <= 0
  49. Serial.println();
  50. } // establishContact()void setup() {
  51. // put your setup code here, to run once:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement