add byte methods to RawKey

This commit is contained in:
Daniella / Tove 2024-06-09 22:07:26 +02:00
parent fb459defea
commit 2f47747045
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -45,7 +45,20 @@ public class RawKey extends Key {
* @return encrypted string
*/
public String encryptString(String s) {
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
return new String(encryptBytes(string.getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1);
}
/**
* Decrypts a string
* @param s string to decrypt
* @return decrypted string
*/
public String decryptString(String s) {
return new String(decryptBytes(string.getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1);
}
public byte[] encryptBytes(byte[] bytes) {
bytes = bytes.clone();
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
int len = bytes.length;
int p = eb.length;
@ -55,16 +68,11 @@ public class RawKey extends Key {
bytes[idx] = (byte) ((int) bytes[idx] + (int) eb[j]);
}
}
return new String(bytes, StandardCharsets.ISO_8859_1);
return bytes;
}
/**
* Decrypts a string
* @param s string to decrypt
* @return decrypted string
*/
public String decryptString(String s) {
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
public byte[] decryptBytes(byte[] bytes) {
bytes = bytes.clone();
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
int len = bytes.length;
int p = eb.length;
@ -74,7 +82,7 @@ public class RawKey extends Key {
bytes[idx] = (byte) ((int) bytes[idx] - (int) eb[j]);
}
}
return new String(bytes, StandardCharsets.ISO_8859_1);
return bytes;
}
@Override