Encrypted Love

Karthik  is missing his girlfriend soo badly due to lockdown.he cant make  a video call also because he is having keypad mobile. He even cant message her because if his girlfrined's parents see those type of romantic messages they completely takeaway mobile from her. So he dont wanted to cause her any trouble.

Now being smart he came up with a way to message her. He decided encrypt all his text message and send it to her so that even her parents read those messages they cant understand anything..Everything is fine.

But now the problem is his girlfriend dont know how to decrypt those messages.She asked your help.Now help her to decrypt those messages.

Here are Some Encrypted and Decrypted Messages for you to crack the logic

            Encrypted                                        Decrypted

  • 444-555-666-888-33-999-666-88                    ----            iloveyou
  • 44-444-22-2-22-33                                          ----            hibabe
  • 4-666-666-3-6-666-777-66-444-66-4              ----           goodmorning
  • 8-444-66-66-2-888-2-777-2                            ----           tinnavara

Example:

Input:  str="444-555-666-888-33-999-666-88"
Output: iloveyou

Approach

Java


public class EncryptedLove {
    public static void main(String args[]) {
        String[] f = "444-555-666-888-33-999-666-88".split("-");
        char p = 'a';
        String j = "";
        StringBuilder s = new StringBuilder(f.length);
        for (int i = 0; i < f.length; i++) {
            j = f[i];
            if (j.charAt(0) >= '8')
                p = (char) (97 + (j.charAt(0) - '0' - 2) * 3 + j.length());
            else
                p = (char) (97 + (j.charAt(0) - '0' - 2) * 3 + j.length() - 1);
            s.append(p);
        }

        System.out.println(s);
    }
}


No comments:

Post a Comment