package de.vanitasvitae.enigmandroid.enigma.util; /** * Used to create wiring arrays from strings * Use strings like "E K M F L G D Q V Z N T O W Y H X U S P A I B R C J" as input * Copyright (C) 2015 Paul Schaub This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * @author vanitasvitae */ public class RotorMaker { public static final int l = 26; public static void main(String[] args) { if(args.length == l) makeRotor(args); else if(args.length == 1) makeRotor(prepare(args[0])); else System.out.println("wrong input format!"); } public static void makeRotor(String input) { makeRotor(prepare(input)); } /** * Prepare the string (add spaces) * @param in input string * @return prepared string */ public static String[] prepare(String in) { String[] out = new String[l]; int pos = 0; for(char x : in.toCharArray()) { if(x != ' ') { try { out[pos] = ""+x; } catch (ArrayIndexOutOfBoundsException e) { System.out.println("String too long!"); return null; } pos++; } } if(pos!=l) { System.out.println("String too short!"); return null; } return out; } /** * Generate Array initializer for the given rotor configuration * @param input String describing the rotor */ public static void makeRotor(String[] input) { if(input.length != l) System.out.println("Wrong length! Input must have length "+l+"!"); else { Integer[] out1 = new Integer[l]; for(int i=0; i