Skip to content

Instantly share code, notes, and snippets.

@simekadam
Created April 21, 2011 09:08
Show Gist options
  • Save simekadam/934030 to your computer and use it in GitHub Desktop.
Save simekadam/934030 to your computer and use it in GitHub Desktop.
Metoda pro rozparsovani textu pred encryptaci
void prepareStringToEncrypt() {
this.pairsToEncrypt = new HashMap<Integer, String>();
String alterTextToEncrypt = this.textToEncrypt.replaceAll(" ", "");
alterTextToEncrypt = Normalizer.normalize(alterTextToEncrypt, Form.NFD).replaceAll("[^\\p{ASCII}]", "");
alterTextToEncrypt = alterTextToEncrypt.replaceAll("[^A-Z]", "");
//System.out.println( "e "+this.password+" "+alterTextToEncrypt);
int increment = 0;
int index = 0;
if (alterTextToEncrypt.length() % 2 != 0) {
alterTextToEncrypt = alterTextToEncrypt.concat("X");
}
for (char ch : alterTextToEncrypt.toCharArray()) {
if (increment % 2 == 0) {
this.pair = String.valueOf(ch);
increment++;
} else {
//ZDE POKUD JE KLIC RADIO, TAK PRI ROVNOSTI PO SOBE JDOUCICH DVOU ZNAKU PRIDAM X
if (this.password.equals("RADIO")) {
if (String.valueOf(ch).equals(this.pair)) {
this.pair += getFiller();
increment++;
this.pairsToEncrypt.put(index++, this.pair);
this.pair = String.valueOf(ch);
increment++;
} else {
this.pair += String.valueOf(ch);
//System.out.print(pair+" ");
this.pairsToEncrypt.put(index++, this.pair);
increment++;
}
} else {
//STANDARDNI PRIPAD, ZDE NEPRIDAVAM X MEZI STEJNE ZNAKY VE DVOJICI
this.pair += String.valueOf(ch);
//System.out.print(pair+" ");
this.pairsToEncrypt.put(index++, this.pair);
increment++;
}
}
if (alterTextToEncrypt.length() % 2 != 0) {
alterTextToEncrypt = alterTextToEncrypt.concat("X");
}
}
//System.out.println("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment