src/lib/Services/EncryptionService.js
/**
     * Creates a random M4 Enigma Configuration.
     * Billions of possible configurations.
     * @returns {Object}: configuration generated.
     */
Creates a random M4 Enigma Configuration.
Billions of possible configurations.
@returns {Object}: configuration generated.
Creates a random M4 Enigma Configuration . Billions of possible configurations . @returns { Object } : configuration generated .
static randomizeConfiguration() {
        var rotors = ["i", "ii", "iii", "iv", "v", "vi", "vii", "viii"];
        var reflectors = ["ukw-b", "ukw-c", "b-thin", "c-thin"];
        var greeks = ["beta", "gamma"];
        var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
        var count, last;
        count = 0;
        var pluggins = [];
        last = EncryptionService.randomNumber(26);
        while (pluggins.length < 6) {
            if (pluggins.indexOf(alphabet[last]) === -1) {
                pluggins[count] = alphabet[last];
                count += 1;
            }
            last = EncryptionService.randomNumber(26);
        }
        var selrotors = [];
        last = EncryptionService.randomNumber(8);
        count = 0;
        while (selrotors.length < 3) {
            if (selrotors.indexOf(last) === -1) {
                selrotors[count] = last;
                count += 1;
            }
            last = EncryptionService.randomNumber(8);
        }
        return {
            "code": [alphabet[EncryptionService.randomNumber(26)], alphabet[EncryptionService.randomNumber(26)], alphabet[EncryptionService.randomNumber(26)]],
            "plugboard": {
                [pluggins[0]]: pluggins[1],
                [pluggins[2]]: pluggins[3],
                [pluggins[4]]: pluggins[5]
            },
            "greek": greeks[EncryptionService.randomNumber(1)],
            "rotor1": rotors[selrotors[0]],
            "rotor2": rotors[selrotors[1]],
            "rotor3": rotors[selrotors[2]],
            "reflector": reflectors[EncryptionService.randomNumber(4)]
        };
    }
static randomizeConfiguration ( ) { var rotors = [ "i" , "ii" , "iii" , "iv" , "v" , "vi" , "vii" , "viii" ] ; var reflectors = [ "ukw-b" , "ukw-c" , "b-thin" , "c-thin" ] ; var greeks = [ "beta" , "gamma" ] ; var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" . split ( "" ) ; var count , last ; count = 0 ; var pluggins = [ ] ; last = EncryptionService . randomNumber ( 26 ) ; while ( pluggins . length < 6 ) { if ( pluggins . indexOf ( alphabet [ last ] ) === - 1 ) { pluggins [ count ] = alphabet [ last ] ; count += 1 ; } last = EncryptionService . randomNumber ( 26 ) ; } var selrotors = [ ] ; last = EncryptionService . randomNumber ( 8 ) ; count = 0 ; while ( selrotors . length < 3 ) { if ( selrotors . indexOf ( last ) === - 1 ) { selrotors [ count ] = last ; count += 1 ; } last = EncryptionService . randomNumber ( 8 ) ; } return { "code" : [ alphabet [ EncryptionService . randomNumber ( 26 ) ] , alphabet [ EncryptionService . randomNumber ( 26 ) ] , alphabet [ EncryptionService . randomNumber ( 26 ) ] ] , "plugboard" : { [ pluggins [ 0 ] ] : pluggins [ 1 ] , [ pluggins [ 2 ] ] : pluggins [ 3 ] , [ pluggins [ 4 ] ] : pluggins [ 5 ] } , "greek" : greeks [ EncryptionService . randomNumber ( 1 ) ] , "rotor1" : rotors [ selrotors [ 0 ] ] , "rotor2" : rotors [ selrotors [ 1 ] ] , "rotor3" : rotors [ selrotors [ 2 ] ] , "reflector" : reflectors [ EncryptionService . randomNumber ( 4 ) ] } ; }
Creates a random M4 Enigma Configuration.
Creates a random M4 Enigma Configuration .