public ADFGVX(String name, int transpositionKeyLength) { this.name = name; transpositionKey = new AlphabetVector(transpositionKeyLength, false); transpositionInverseKey = new AlphabetVector(transpositionKeyLength, false); substitutionKey = new Alphabet36Vector(); substitutionInverseKey = new Alphabet36Vector(); substitutionKey.acceptErrors = true; substitutionInverseKey.acceptErrors = true; resetTranspositionKey(); resetSubstitutionKey(); }
public void decodeSubstitution(ADFGVXVector interim, Alphabet36Vector plain) { if (interim.length % 2 != 0) { //hack, to allow uneven length adfgvx texts interim.append("A"); } plain.length = 0; for (int i = 0; i < interim.length; i += 2) { int v1 = interim.TextInInt[i]; int v2 = interim.TextInInt[i + 1]; if (v1 == -1 || v2 == -1) { plain.append(-1); } else { plain.append(this.substitutionInverseKey.TextInInt[v1 * 6 + v2]); } } }
public Algorithm(int keyLength, String[] messages, Logger log, int taskId, ThreadingHelper threadingHelper, ADFGVXANalyzerSettings settings, ADFGVXAnalyzer analyzer) { this.analyzer = analyzer; this.threadingHelper = threadingHelper; this.taskId = taskId; this.log = log; this.language = settings.Language; this.deviation = settings.Deviation; this.restarts = settings.Restarts; this.keyLength = keyLength; ciphers = new ADFGVXVector[messages.Length]; int totalPlainLength = 0; int maxPlainLength = 0; for (int m = 0; m < messages.Length; m++) { ciphers[m] = new ADFGVXVector(messages[m].Replace(" ", ""), false); totalPlainLength += ciphers[m].length / 2; maxPlainLength = Math.Max(maxPlainLength, ciphers[m].length / 2); } allPlain = new Alphabet36Vector(totalPlainLength, true); plain = new Alphabet36Vector(maxPlainLength, false); interimCipher = new ADFGVXVector(maxPlainLength * 2, false); }
public void decode(ADFGVXVector cipher, ADFGVXVector interim, Alphabet36Vector plain) { Transposition.decodeWithInverseKey(this.transpositionInverseKey, cipher, interim); decodeSubstitution(interim, plain); }
public void setSubstitutionInverseKey(Alphabet36Vector substitutionInverseKey) { this.substitutionInverseKey.copy(substitutionInverseKey); updateSubstitutionKeyFromInverse(); }