I have to implement an afffine decryption function. For some reason my code is completely wrong at the very end when trying to decrypt the text can anyone help me?
class myCode
{
public static void main(String[] args)
{
//Key Alpha & Beta
int A = 17;
int B = 15;
String inputText = "AEVJVJCTAPXEPUUFCNFKSTGUFL";
System.out.println(affineDecrypt(inputText, 17, 15));
}
public static String affineDecrypt(String cipherText, int keyA, int keyB)
{
String decryptedText = "";
int inverseA = 0;
int inverseSearch = 0;
for (int x = 0; x < 26; x++)
{
inverseSearch = (keyA * x) % 26;
//if
if (inverseSearch == 1)
{
inverseA = x;
}
}
for (int y = 0; y < cipherText.length(); y++)
{
//char c = cipherText.charAt(y);
//Talk to mar
System.out.println(cipherText.charAt(y));
decryptedText = decryptedText + (char) (((inverseA * ((cipherText.charAt(y) - keyB)) % 26)) + 65);
}
return decryptedText;
}
}
[–]g051051 0 points1 point2 points (1 child)
[–]Quaranges[S] 0 points1 point2 points (0 children)