Skip to content
Snippets Groups Projects

Updated Crypter

Merged Jere Salmensaari requested to merge jere-dev into master
2 files
+ 42
3
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -3,6 +3,7 @@ package noteApp.utils.AES;
import com.sun.security.jgss.GSSUtil;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.*;
@@ -203,7 +204,7 @@ public class Crypter {
String cryptedString = "";
for (int i = 0; i < loopLength; i++) {
if ((i+1)*16 >= note.length()) {
state = splitInto16Bytes(note);
state = splitInto16Bytes(note.substring(i*16));
} else {
state = splitInto16Bytes(note.substring(i*16, (i+1)*16));
@@ -335,7 +336,7 @@ public class Crypter {
String decryptedString = "";
for (int i = 0; i < loopLength; i++) {
if ((i+1)*16 >= cipher.length()) {
state = splitInto16Bytes(cipher);
state = splitInto16Bytes(cipher.substring(i*16));
} else {
state = splitInto16Bytes(cipher.substring(i*16, (i+1)*16));
@@ -516,13 +517,24 @@ public class Crypter {
}
/**
* Converts a given int array to it's corresponding ASCII in a String.
* Converts a given int array to it's corresponding ASCII in a String. Removes padding from the end of the String.
* @param input array of 16 bytes.
* @return converted, converted String.
*/
private String convertToString(int[] input) {
Integer endValues[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
String converted = "";
int endValue = input[input.length-1];
if (Arrays.asList(endValues).indexOf(endValue) > -1) {
boolean isRemovable = true;
for (int i = input.length-1; i > input.length- input[input.length-1]; i--) {
isRemovable = input[i] == endValue ? true : false;
}
if (isRemovable) {
input = Arrays.copyOfRange(input, 0, input.length-endValue);
}
}
for (int value: input) {
converted += Character.toString((char)value);
}
@@ -530,4 +542,14 @@ public class Crypter {
return converted;
}
private boolean isInList(int[] list, int value) {
try {
int val = list[value];
return true;
} catch (ArrayIndexOutOfBoundsException e) {
return false;
}
}
}
Loading