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: Enigma.cpp
- Revision:
- 3:9590c44c9ecd
- Parent:
- 2:ee55abc2b6a2
- Child:
- 4:107a360171fe
diff -r ee55abc2b6a2 -r 9590c44c9ecd Enigma.cpp
--- a/Enigma.cpp Tue Sep 24 08:52:11 2019 +0000
+++ b/Enigma.cpp Tue Sep 24 09:17:40 2019 +0000
@@ -155,6 +155,7 @@
// Initialize reflector.
_reflector = const_cast<uint8_t*>(REFLECTOR);
+ // Connect the plugboard
_plugboard = new uint8_t[cords][2];
for (size_t i = 0; i < cords; i++) {
for (size_t j = 0; j < 2; j++) {
@@ -169,6 +170,7 @@
* @retval out Pointer to a byte array to store the encrypted bytes in.
* @param in Pointer to a byte array to be encrypted.
* @param len Length of the byte array.
+ * @retval Pointer to a byte array containing the encrypted bytes.
*/
uint8_t* Enigma::encrypt(uint8_t* out, const uint8_t* in, size_t len)
{
@@ -182,7 +184,7 @@
for (size_t i = 0; i < len; i++) {
uint8_t byte = in[i];
- // Swap bytes connected with cords
+ // Swap bytes cross-connected with cords
found = false;
for (size_t j = 0; j < _cords; j++) {
for (size_t k = 0; k < 2; k++) {
@@ -224,7 +226,7 @@
byte = _entryWheel[_mod(_find(byte, _middleRotor) - middleRotorPos + rightRotorPos)];
byte = _entryWheel[_mod(_find(byte, _rightRotor) - rightRotorPos)];
- // Swap bytes connected with cords
+ // Swap bytes cross-connected with cords
found = false;
for (size_t j = 0; j < _cords; j++) {
for (size_t k = 0; k < 2; k++) {
@@ -247,10 +249,11 @@
/**
* @brief Decrypts a byte array.
- * @note Decryption capability is extended from 26 chars to all 256 bytes.
+ * @note Decryption capability is extended from 26 upper case letters to any byte.
* @retval out Pointer to a byte array to store the decrypted bytes in.
* @param in Pointer to a byte array to be decrypted.
* @param len Length of the byte array.
+ * @retval Pointer to a byte array containing the decrypted bytes.
*/
uint8_t* Enigma::decrypt(uint8_t* out, const uint8_t* in, size_t len)
{
@@ -328,7 +331,10 @@
memset(modified, 0, _len);
for (size_t i = 0; i < _len; i++) {
+
if (modified[i] != 0) {
+
+
continue;
}
@@ -397,4 +403,4 @@
}
return -1;
-}
+}
\ No newline at end of file