Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. -- hello_world.c --
  3. -- Christine Chen --
  4. -- Fall 2013 --
  5. -- --
  6. -- Updated Spring 2015 --
  7. -- Yi Liang --
  8. -- --
  9. -- For use with ECE 385 Experiment 9 --
  10. -- UIUC ECE Department --
  11. ---------------------------------------------------------------------------*/
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. #define to_hw_port (volatile char*) 0x00000000 // actual address here
  18. #define to_hw_sig (volatile char*) 0x00000000 // actual address here
  19. #define to_sw_port (char*) 0x00000000 // actual address here
  20. #define to_sw_sig (char*) 0x00000000 // actual address here
  21.  
  22. char charToHex(char c)
  23. {
  24. char hex = c;
  25.  
  26. if (hex >= '0' && hex <= '9')
  27. hex -= '0';
  28. else if (hex >= 'A' && hex <='F')
  29. {
  30. hex -= 'A';
  31. hex += 10;
  32. }
  33. else if (hex >= 'a' && hex <='f')
  34. {
  35. hex -= 'a';
  36. hex += 10;
  37. }
  38. return hex;
  39. }
  40.  
  41. char charsToHex(char c1, char c2)
  42. {
  43. char hex1 = charToHex(c1);
  44. char hex2 = charToHex(c2);
  45. return (hex1 << 4) + hex2;
  46. }
  47.  
  48. // TODO: AES Encryption related function calls
  49.  
  50. int main()
  51. {
  52. int i;
  53. unsigned char plaintext[33]; //should be 1 more character to account for string terminator
  54. unsigned char key[33];
  55.  
  56. // Start with pressing reset
  57. *to_hw_sig = 0;
  58. *to_hw_port = 0;
  59. printf("Press reset!\n");
  60. while (*to_sw_sig != 3);
  61.  
  62. while (1)
  63. {
  64. *to_hw_sig = 0;
  65. printf("\n");
  66.  
  67. printf("\nEnter plain text:\n");
  68. scanf ("%s", plaintext);
  69. printf ("\n");
  70. printf("\nEnter key:\n");
  71. scanf ("%s", key);
  72. printf ("\n");
  73.  
  74. // TODO: Key Expansion and AES encryption using week 1's AES algorithm.
  75.  
  76. // TODO: display the encrypted message.
  77. printf("\nEncrypted message is\n");
  78.  
  79. // Transmit encrypted message to hardware side for decryption.
  80. printf("\nTransmitting message...\n");
  81.  
  82. for (i = 0; i < 16; i++)
  83. {
  84. *to_hw_sig = 1;
  85. *to_hw_port = encryptedMsg[i]; // encryptedMsg is your encrypted message
  86. // Consider to use charToHex() if your encrypted message is a string.
  87. while (*to_sw_sig != 1);
  88. *to_hw_sig = 2;
  89. while (*to_sw_sig != 0);
  90. }
  91. *to_hw_sig = 0;
  92.  
  93. // Transmit encrypted message to hardware side for decryption.
  94. printf("\nTransmitting key...\n");
  95.  
  96. //TODO: Transmit key
  97.  
  98. printf("\n\n");
  99.  
  100. while (*to_sw_sig != 2);
  101. printf("\nRetrieving message...\n");
  102. for (i = 0; i < 16; ++i)
  103. {
  104. *to_hw_sig = 1;
  105. while (*to_sw_sig != 1);
  106. str[i] = *to_sw_port;
  107. *to_hw_sig = 2;
  108. while (*to_sw_sig != 0);
  109. }
  110.  
  111. printf("\n\n");
  112.  
  113. printf("Decoded message:\n");
  114.  
  115. // TODO: print decoded message
  116. }
  117.  
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement