You are on page 1of 2

Lets say;

(a = 1), (A = 1), (b = 2), (B = 2), ..., (t = 20), (T = 20) and so on,


for the sake of calculation.
But,
(a != A), (b != B), ..., (t != T) and so on,
for the sake of case sensitivity.
Now let there be an encryption method where every letter is replaced by another
letter as below:
As (b = 2), It would be replaced by (2+2) = (4 = d).
As (B = 2), It would be replaced by (2+2) = (4 = D).
As (c = 3), It would be replaced by (3+3) = (6 = f).
As (C = 3), It would be replaced by (3+3) = (6 = F).
So case sensitivity should be maintained.
If the result of the adding process becomes greater than 26,
then 26 should be substracted from the result.
So, if we wish to encrypt (o):
As (o = 15),
It would be replaced by:
= (15+15)
= As (30) > 26
= (30-26)
= (4 = d)
In the same way,
(O) would be encrypted to (D).
Full encryption reference:
(a) -> [b] <- (n)
(b) -> [d] <- (o)
(c) -> [f] <- (p)
(d) -> [h] <- (q)
(e) -> [j] <- (r)
(f) -> [l] <- (s)
(g) -> [n] <- (t)
(h) -> [p] <- (u)
(i) -> [r] <- (v)
(j) -> [t] <- (w)
(k) -> [v] <- (x)
(l) -> [x] <- (y)
(m) -> [z] <- (z)
And,
(A) -> [B] <- (N)
(B) -> [D] <- (O)
(C) -> [F] <- (P)
(D) -> [H] <- (Q)
(E) -> [J] <- (R)
(F) -> [L] <- (S)
(G) -> [N] <- (T)
(H) -> [P] <- (U)
(I) -> [R] <- (V)
(J) -> [T] <- (W)
(K) -> [V] <- (X)
(L) -> [X] <- (Y)
(M) -> [Z] <- (Z)
This is certainly a problem of this encryption method,
as only half of the alphabets would be uniquely distinguishable after encryption
.
Now, I would like to ask you;
if 2 given strings would be equal or not,
after they are encrypted;
using the above encryption method.
Create a function,
that would receive 2 strings as parameters and would return true,
if those 2 become equal after encryption;
or would return false,
if they are unique.
Example:
"OK" and "OX" would be equal.
"OK" and "Ok" would not be equal.
"ZOO" and "BOO" would not be equal.
"Ok" and "Ox" would be equal.
"Cat" and "Pag" would be equal.
"Cat" and "Bag" would not be equal.
... ... ...
Solution:
public class Question {
public static void main(String[] args) {
System.out.println(equalityCheck("ZOO","BOO"));
}
public static boolean equalityCheck(String first, String second) {
if (first.length() != second.length()) {
return false;
}
for (int i=0; i<first.length(); i++) {
if ( (((first.charAt(i))*2)%26) != (((second.charAt(i))*
2)%26) ) {
return false;
}
}
return true;
}
}

You might also like