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-22
- Revision:
- 0:3381509d20af
- Child:
- 1:ad5fb6f2ab3c
File content as of revision 0:3381509d20af:
#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);
}
}