Copy and paste Enigma

I had the dumb idea of recreating "The Enigma Machine" in SDL and running my passphrases through it to create a bit of an extra secure password from what is otherwise an easy to remember sentence. Whenever I need to recreate the password I make sure the plugs and rotors are set correctly and type the phrase again. Copy/paste the result and it's done.

But there's at least one flaw in my plan. How safe is copy/pasting a password?
Some possible solutions so far:

I could set a time-out that clears the copy/paste buffer (clipboard) X seconds after copying the password. It's easier to push to the clipboard by hitting a button anyhow, so a short timer from that click would not take much time to set up.

I could create the enigma window as "Always on top" with a lowered opacity when focus is lost so the complicated passphrase will be visible while I type it in the window directly below.

Drag and drop would be my final resort since SDL doesn't support initiating a drag and drop, so I'd have to figure that out first.
Last edited on
Existing password managers have already solved this problem. They just wait a certain number of seconds after you copy and then they clear the clipboard. The only issue is that there's no way to isolate processes from the clipboard, so when you copy, everything that's currently running can see what you copied.

There's an argument to be made that if you're already running a dodgy process, you've already lost, but I feel it would be safer if the manager sent the keystrokes directly to the target window. Hypothetically, a process might be logging the clipboard due to oversight, or because the designer didn't realize that it could be an issue.
I had the dumb idea of recreating "The Enigma Machine" in SDL and running my passphrases through it to create a bit of an extra secure password from what is otherwise an easy to remember sentence. Whenever I need to recreate the password I make sure the plugs and rotors are set correctly and type the phrase again. Copy/paste the result and it's done.

This sounds like you "re-create" the password using a fixed algorithm (Enigma) with a fixed initial state (i.e. initial rotor/plugs configuration). Since the result will always be the same, this is not secure at all! You could, just as well, hard-code the resulting password 😏

Think of Kerckhoff's Principle: You must assume that the attacker knows your algorithm. And, in your case, the initial state (i.e. initial rotor/plugs configuration) is considered to be an integral part of the algorithm, because it is totally fixed.

https://www.techtarget.com/whatis/definition/Kerckhoffs-principle

So, for the very least, the initial state (i.e. initial rotor/plugs configuration) should be derived from a "master" password, which muster be re-entered every time – in a way that different "master" passwords result in a different initial state with very high probability.

But: Now you have to remember the "master" password instead of the "computed" password itself. So, this does not make a whole lot of sense – unless you also include a site-specific "id" into the calculation, so that many site-specific passwords can be generated from a single "master" passwords. That's where the idea starts making sense. And that is exactly what a lot of modern password managers do 😎


Also, unless you want to implement Enigma for educational purposes, just use the much more secure and readily-available PBKDFv2:
https://en.wikipedia.org/wiki/PBKDF2
Last edited on
This sounds like you "re-create" the password using a fixed algorithm (Enigma machine) with a fixed initial state (i.e. initial rotor/plugs configuration). If so, this is not secure at all. You could, just as well, hard-code the resulting password 😏

Yes and no, since I'm the only person that would know the initial state of the machine, they are still left guessing what that state is. The rotors will be seeded at random each time I open the program, and it would be up to me to re-seed to get to the original state. I really like the idea of a master string that would seed the machine for me, that would be a huge time-saver.

I've done a couple of tests against https://www.passwordmonster.com/ and have gotten results like "18 million trillion trillion years", off of the phrase "Hello how is the weather" -> "Wipsl qix os pbd eovldzg" so I'm pretty confident that I'm on a good track.

One of the largest weaknesses of the enigma machine is the length of the message and commonly repeated phrases over a large sample size.

My main weakness is going to be the security of my machine: who's to say that someone isn't taking snapshots of my screen every second and watching 8 hours of my day as a 8 minute video, or that a key-logger isn't logging my keyboard, or that someone isn't snooping on my network connection? How much do I trust the BIOS/hardware designer? ...And there's my paranoia setting in.

The original question was whether copy/paste was a good solution, and the answer is that it's not great but that it is commonly used for the purpose. I'll leave it as an optional button that wipes the clipboard after 2 seconds.

Thank you for all the thoughts Kigar.
I'll post a github link if I get it looking/working good enough (with a disclaimer that it's a hobby machine, not meant for actual service).
Yes and no, since I'm the only person that would know the initial state of the machine, they are still left guessing what that state is. The rotors will be seeded at random each time I open the program, and it would be up to me to re-seed to get to the original state. I really like the idea of a master string that would seed the machine for me, that would be a huge time-saver.

Is the initial state hard-coded in the program, or do you have to manually enter it every time?

Only in the latter case you can argue that the initial state is not a fixed part of the algorithm, but is considered a "secret" key.

But even then, the resulting password will always be exactly the same, for the same key (initial state).

It means that, instead of remembering the password itself, you now have to remember the initial state. What did you gain by this ???

IMHO, it only makes sense, if the resulting password depends on two things: The initial state (secret key) plus an additional per-site "id", so that the same initial state (secret key) can be used to generate many different passwords for different sites...

Also, as mentioned before, I think it's better to derive the initial state from a "master" password, as that's far easier to remember.

However, if we have a "master" password, I think it would be far better to simply use PBKDF2 to derive a binary key (e.g. 256 bits) from the given "master" password, then use that key to seed a CSRNG (cryptographically secure pseudorandom number generator), and finally use the CSRNG output to generate the password(s) of arbitrary length - instead of using "Enigma" with all of its well-known flaws.

My main weakness is going to be the security of my machine: who's to say that someone isn't taking snapshots of my screen every second and watching 8 hours of my day as a 8 minute video, or that a key-logger isn't logging my keyboard, or that someone isn't snooping on my network connection? How much do I trust the BIOS/hardware designer? ...And there's my paranoia setting in.

It's a matter of the attack model that you assume. If you assume that an attacker has already compromised your machine, so that the attacker can read your computer's memory or record all key strokes, then you are pretty much "doomed" anyways 😏

...except, maybe, by managing your passwords/key on a separate hardware security module (e.g. YubiKey). Note that a YubiKey, or similar devices, also contain a unique "master" key, which is burnt into device and which never leaves the device. This "master" key plus a site-specific "credential id" (a random number that is generated the first time you visit a specific site) is used to derive the site-specific keys.
Last edited on
Yes, the state would be entered every time, the previous state is not stored once the program is closed.

I really do like the idea of a master key to help instance the state.

The state will also have a graphical representation on the screen, I want to be able to drag the terminals on the plugs to different positions at a whim.

I just think it would be cool to own a virtual "Enigma Machine". The program itself will be a toy, I'm not going to distribute this as if it is meant to keep your secrets away from hackers, but I do want it to be as safe as possible, I'm not going to distribute it at all if it would weaken a person's security. (Which is why I'm going to use it personally as described in the prompt).

Thank you again, I appreciate your help.
Still, I think you could simply be doing something like this:

(written in Java, for the sake of simplicity)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class PWGen {

    private static final int ITERATIONS = 99999;
    private static final int KEY_SIZE = 512;
    private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";

    public static String generate(final String masterPasswd, final byte[] salt, final int length) throws Exception {
        // Derive key from "master" password and salt (id)
        final SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
        final char[] secret = masterPasswd.toCharArray();
        final PBEKeySpec spec = new PBEKeySpec(secret, salt, ITERATIONS, KEY_SIZE);
        final byte[] key = skf.generateSecret(spec).getEncoded();
        
        // Initialize CSRNG with our key
        final SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        random.setSeed(key);
        
        // Now generate the password!
        final char[] chars = CHARS.toCharArray();
        final StringBuilder password = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            password.append(chars[random.nextInt(chars.length)]);
        }

        return password.toString();
    }

    public static String generate(final String masterPasswd, final long siteId, final int length) throws Exception {
        return generate(masterPasswd, toByteArray(mix64(siteId)), length);
    }

    private static byte[] toByteArray(final long value) {
        return ByteBuffer.allocate(Long.BYTES).putLong(value).array();
    }

    private static long mix64(long z) {
        z = (z ^ (z >>> 30)) * 0xbf58476d1ce4e5b9L;
        z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL;
        return z ^ (z >>> 31);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Main {
    
    public static void main(String[] args) throws Exception {
        final int PASSWORD_LEN = 64;
        
        System.out.println(PWGen.generate("ThisIsMyMasterSecrect", 42, PASSWORD_LEN));
        System.out.println(PWGen.generate("ThisIsMyMasterSecrect", 43, PASSWORD_LEN));
        System.out.println(PWGen.generate("ThisIsMyMasterSecrect", 44, PASSWORD_LEN));

        System.out.println("--");

        System.out.println(PWGen.generate("ThisIsMyMasterSecRect", 42, PASSWORD_LEN));
        System.out.println(PWGen.generate("ThisIsMyMasterSecRect", 43, PASSWORD_LEN));
        System.out.println(PWGen.generate("ThisIsMyMasterSecRect", 44, PASSWORD_LEN));
    }
}
JGxujjAknD_u6judWDBsYZPAG2EOtyXyrpkfn27UFSj1rRZJiuIctfMPSwpeBNWj
eOF8SB_s73KuX0p4yVq7b_G2eCvInECjQZlDKRjs3VaQ0IsjU8PieyBHliylNsoW
aCph7pM3D_RQqM4_QI0lx44G8SiGlNIRQL3IlM05_ztEd6m0Z3LMbprprB2dVBWs
--
XaX9zPeGZsOW9jY5E6wsGwX4lYSQ2TZuJ4pctjMtLUcfJJdO52nLy60gR3JDXl8n
lAmnmqGVqU2yvdbXvaTkR8BS3yTKLLKr6Qf4iRPevU7QNZf4IKsGmgEzwg6e5YAK
dYbBzKAoxdCphr_uqmIJ5U_xIDi2hHTHCgODwnATQCHe7RHv2QKJ7tOt6Gjreggn



BTW: If you really want to include the Enigma machine in the process, you could follow the same approach as above, and then use the CSRNG to generate a pseudo-random initial Enigma configuration – rather than generating a pseudo-random password directly.
Last edited on
Also remember how the Enigma machine was 'cracked' during WWII...
https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma
^^ IIRC without reading all that, one (of many) key problem was they were sending the same messages frequently, like "nothing to report" or whatever their default check-in message was. It would be the same length every time, and they had a really good idea what it said... with this kind of crypto if you have a good example of input and encrypted input both, you can often unravel it.
As of a few years ago there were at least 3 believed to be unbroken Enigma messages. There is a distributed computing project, Enigma@Home, set up to crack them.

http://www.enigmaathome.net/
Topic archived. No new replies allowed.