Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:3381509d20af
- Child:
- 1:ad5fb6f2ab3c
diff -r 000000000000 -r 3381509d20af main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Sep 22 21:14:33 2019 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+#include "Enigma.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1);
+Enigma enigma(Enigma::ROTOR_IV, Enigma::ROTOR_I, Enigma::ROTOR_III, 126, 247, 14); // Selects rotors and sets initial position
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+int main()
+{
+ char message[] = "Hello World!"; // A message to encrypt and then decript
+ char* encrypted = new char[strlen(message)];
+ char* decrypted = new char[strlen(message) + 1];
+
+// enigma.genRotorWiring("IV", 213); // generates new wiring for rotor IV
+// enigma.genReflectorWiring(6); // generates new wiring for the reflector
+
+ while (true) {
+ pc.printf("-------------------\r\n");
+ pc.printf("%s\r\n", message);
+
+ enigma.encrypt(encrypted, message, strlen(message));
+ for (size_t i = 0; i < strlen(message); i++) {
+ pc.putc(encrypted[i]);
+ }
+
+ pc.printf("\r\n");
+
+ enigma.decrypt(decrypted, encrypted, strlen(message));
+ decrypted[strlen(message)] = '\0';
+ pc.printf("%s\r\n", decrypted);
+
+ led1 = !led1;
+ wait(2);
+ }
+}