package com.gmail.lukas.karnowski.enigma;
import com.gmail.lukas.karnowski.enigma.roller.Roller;
import com.gmail.lukas.karnowski.enigma.util.Letter;
import lombok.Getter;
import lombok.NonNull;
/**
* This is the abstract superclass for all types of enigmas
*
* @author Lukas
*/
public abstract class Enigma {
/**
* Name of this enigma
*/
@Getter protected final String name;
/**
* Rollers of the enigma
*/
@Getter protected final Roller[] rollers;
/**
* Create a new enigma object
*
* @param name The name of the enigma
* @param rollerAmount The amount of rollers, this enigma uses
*/
protected Enigma( @NonNull final String name, int rollerAmount ) {
this.name = name;
rollers = new Roller[rollerAmount];
}
/**
* Create a new enigma object with the simple class name
*
* @param rollerAmount The amount of rollers, this enigma uses
*/
protected Enigma( int rollerAmount ) {
this.name = getClass().getSimpleName();
rollers = new Roller[rollerAmount];
}
/**
* Use for encrypting a whole string
*
* @return An array of encrypted letters in the right order
*/
public Letter[] stringInput( @NonNull final String input ) {
Letter[] letters = new Letter[input.length()];
int counter = 0;
for ( char c : input.toCharArray() ) {
Letter letter = Letter.fromChar( c );
letters[counter] = keyInput( letter );
++counter;
}
return letters;
}
/**
* This is like, pressing a key on the keyboard of the enigma
*
* @param inputLetter The key typed
* @return The result letter of the encryption
*/
public abstract Letter keyInput( @NonNull final Letter inputLetter );
}