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.
main.cpp
- Committer:
- hudakz
- Date:
- 2019-09-23
- Revision:
- 1:ad5fb6f2ab3c
- Parent:
- 0:3381509d20af
- Child:
- 2:ac7a3cea1757
File content as of revision 1:ad5fb6f2ab3c:
#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);
/**
* @brief
* @note
* @param
* @retval
*/
int main()
{
char message[] = "Hello World!"; // A message (byte array) to encrypt.
uint8_t* encrypted = new uint8_t[strlen(message)];
uint8_t* decrypted = new uint8_t[strlen(message) + 1];
// Helper functions for maintenance only:
//enigma.genRotorWiring("IV", 213); // Generate new wiring for rotor IV.
//enigma.genReflectorWiring(6); // Generate new wiring for the reflector.
while (true) {
pc.printf("------------------------------\r\n");
pc.printf("%s\r\n\r\n", message);
// Encrypt and print the encrypted message.
enigma.encrypt(encrypted, (uint8_t*)message, strlen(message));
for (size_t i = 0; i < strlen(message); i++) {
pc.putc(encrypted[i]);
}
pc.printf("\r\n\r\n");
// Decrypt the 'encrypted' array and print.
enigma.decrypt(decrypted, encrypted, strlen(message));
decrypted[strlen(message)] = '\0'; // Terminate the c-style string (needed for 'printf').
pc.printf("%s\r\n\r\n", decrypted);
led1 = !led1;
wait(2);
}
}