Code mesin rotor di java
public class MesinRotor extends MonoClassicCipher {
private int posisi;
private SubtitutionCipher subCiphers[];
public MesinRotor(SubtitutionCipher[] subCiphers) {
this.subCiphers = subCiphers;
this.posisi = 0;
}
public int enkripsi(int x) {
int y = subCiphers[posisi].enkripsi(x);
posisi = (posisi + 1) % subCiphers.length;
return y;
}
public int dekripsi(int y) {
int x = subCiphers[posisi].dekripsi(y);
posisi = (posisi + 1) % subCiphers.length;
return x;
}
public void reset() {
posisi = 0;
}
}
public class MesinRotor extends MonoClassicCipher {
private int posisi;
private SubtitutionCipher subCiphers[];
public MesinRotor(SubtitutionCipher[] subCiphers) {
this.subCiphers = subCiphers;
this.posisi = 0;
}
public int enkripsi(int x) {
int y = subCiphers[posisi].enkripsi(x);
posisi = (posisi + 1) % subCiphers.length;
return y;
}
public int dekripsi(int y) {
int x = subCiphers[posisi].dekripsi(y);
posisi = (posisi + 1) % subCiphers.length;
return x;
}
public void reset() {
posisi = 0;
}
}
Komentar