Skip to content

Commit

Permalink
Fixed ROT encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius Musiolik authored and Darius Musiolik committed Aug 25, 2016
1 parent 751de33 commit ae52434
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Binary file added dist/DMEdit.jar
Binary file not shown.
29 changes: 15 additions & 14 deletions src/dm/edit/dmhelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public void write(File file, String content) {
}

FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
try (BufferedWriter bw = new BufferedWriter(fw)) {
bw.write(content);
}

} catch (IOException e) {
e.printStackTrace();
Expand All @@ -76,7 +76,7 @@ public int alert_input(String msg) {
return 0;
}
if (ret.contains(" ")) {
this.info("Error!");
dmhelper.info("Error!");
return 0;
}

Expand All @@ -88,16 +88,15 @@ public int alert_input(String msg) {
String cipher(String input, int cryptvalue){
String s = "";
int len = input.length();

for(int x = 0; x < len; x++) {
char c = (char)(input.charAt(x) + cryptvalue);
if (c > 'z')
s += (char)(input.charAt(x) - (26 - cryptvalue));
else

s += (char)(input.charAt(x) + cryptvalue);

}
return s;
}
}


//deencrypt
String uncipher(String input, int cryptvalue){
Expand All @@ -106,12 +105,14 @@ String uncipher(String input, int cryptvalue){

for(int i = 0; i < len; i++) {
char c = (char)(input.charAt(i) - cryptvalue);
if (c > 'z')
s += (char)(input.charAt(i) + (26 + cryptvalue));
else
if (c > 'z') {
s += (char)(input.charAt(i) + (27 + cryptvalue));
}
else {
s += (char)(input.charAt(i) - cryptvalue);
}
return s;
}
return s;
}

}
}

0 comments on commit ae52434

Please sign in to comment.