-
Notifications
You must be signed in to change notification settings - Fork 3
Novel Data Idea
Terran edited this page Apr 24, 2018
·
4 revisions
First, tool adds a class called Decryptor to the app, with:
- decrypt(string encrypted) that returns the decrypted string
- intDecrypt(string encrypted) that returns decrypted int
- String original = "original string";
- tool has method encrypt(string original) to return string "3ncrypt3d 5tr1ng"
- change line into var = Decryptor.decrypt("3ncrypt3d 5tr1ng");
- Basically .decrypt(string encrypted) performs the algorithm for decryption
- At runtime .decrypt will be called and original = "original string" again
- source code: int i = 3;
- tool: intEncryptor(int i) returns string "3ncrypt3d 1nt"
- source code modified: int i = Decyptor.intDecrypt("3ncrypt3d 1nt");
- source code added method: Decyptor.intDecrypt(string encryptedInt) takes "3ncrypt3d 1nt" and returns 3
-
1.1 have multiple encryptors methods (encryptor1,2,3,...)
-
1.2 when encrypting, use a random encryptor
-
1.3 append the encryptor number onto the start of the encrypted string
-
1.4 so encryptor1 returns "13ncrypt3d 5tr1ng", encryptor2 returns "23ncrypt3d 5tr1ng"
-
1.5 base64 encode the encrypted string
-
4.1 Decryptor.decrypt first base 64 decodes to get encrypted string "23ncrypt3d 5tr1ng"
-
4.2 switches on the first character of encrypted string
-
4.3 the cases perform different types of decryption accordingly
/**
In our tool
**/
public class DataEncryptor {
private final int NUMBER_OF_ENCRYPTORS = 5;
private static int encryptor = 0;
public void toolEncrypt(Node n) { //it can take anything
/* TODO:
Terran what are the possible Nodes that can be passed in for modification?
can make this random :)
*/
if(isString){
//get the part to modify
SomeType actualStringPart; //TODO the part that contains the actual string
if(isParameter) {
actualStringPart = ;
} else if(isAssignment) {
actualStringPart = ;
}
//find encryptor
encryptor++;
encryptor = encryptor % NUMBER_OF_ENCRYPTORS;
//encrypt the string
string encryptedString = stringEncrypt(s, encryptor);
//append encryptor
string appendedString = encryptor+base64String; //append encryptor identifier to start
//base 64 whole thing
string base64String = Base64.getEncoder().encodeToString(encryptedString.getBytes(StandardCharsets.UTF_8));
//do the modification
actualStringPart = "Decryptor.decrypt(\"" + base64String + "\")"; //might need to import Decryptor or use fully qualified name
} else if(isInt) {
//get the part to modify
SomeType actualIntPart; //TODO the part that contains the actual int
if(isParameter) {
actualStringPart = ;
} else if(isAssignment) {
actualStringPart = ;
}
string obfuscatedInt = ; //Sejal's number encryptor
//do the modification
actualIntPart = "Decryptor.intDecrypt(\"" + obfuscatedInt + "\")"; //might need to import
}
}
}
public string stringEncrypt(string original, int encryptor) {
string encryptedString;
switch(encryptor) {
case 0:
encryptedString = vignereEncrypt(original);
break;
case 1:
encryptedString = substitutionEncrypt(original);
break;
case 2:
encryptedString = oneTimePadEncrypt(original);
break;
case 3:
encryptedString = CaesarEncrypt(original);
break;
case 4:
encryptedString = AtbashEncrypt(original);
break;
}
return encryptedString;
}
}
/**
To be added to obfuscated app code, then obfuscate it too
**/
public class Decryptor {
public string decrypt(string base64String) {
//base64 decode
byte[] decodedBytes = Base64.getDecoder().decode(base64String);
string decodedString = new String(decodedBytes);
//get encryptor
int toSwitch = Character.getNumericValue(decodedString.charAt(0));
//get rid of encryptor
string onlyEncryption = decodedString.substring(1);
switch(toSwitch) {
case 0:
decryptedString = vignereDecrypt(onlyEncryption);
break;
case 1:
decryptedString = substitutionDecrypt(onlyEncryption);
break;
case 2:
decryptedString = oneTimePadDecrypt(onlyEncryption);
break;
case 3:
decryptedString = CaesarDecrypt(onlyEncryption);
break;
case 4:
decryptedString = AtbashDecrypt(onlyEncryption);
break;
}
}
public int intDecrypt(string obfuscatedInt) {
//TODO: insert or replace with Sejal's number decryptor, remember to change the modification the tool does
}
}
/**
inserts the Decryptor into the app files
**/
public void insertDecryptor() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("/ourtool/Decryptor.java"));
BufferedWriter writer = new BufferedWriter(new FileWriter(new File("/FindFood/app/src/main/java/nz/co/g1/a702/findfood/ecryptor.java")));
String line = null;
while ((line=reader.readLine()) != null) {
writer.write(line);
}
reader.close();
writer.close();
}
- AtbashEncrypt, AtbashDecrypt
- substitutionEncrypt, substitutionDecrypt
- CaesarEncrypt, CaesarDecrypt
- vigenereEncrypt, vigenereDecrypt
- oneTimePadEncrypt, oneTimePadDecrypt
- generateAtbashOrderedString
- convertToAlphabetIntegerArray
- encryptDigit, decryptDigit (for numbers)
- generateNumberEncryptionHashMap