Click to See Code


public class ROT13

{

    public static void main(String args[])

    {

     // method calls

     System.out.println(encrypt("Hello")); //method call encrypt

     System.out.println(decrypt("uryyb")); //method call decrypt

    }

    // methods here

   
    //ROT 13
    public static String encrypt(String s){

        s = s.toLowerCase();

        char [] shiftS = s.toCharArray();

        for (int i = 0; i<shiftS.length;i++)

        {

            if(shiftS[i] >= 97 && shiftS[i] <= 109)

            {

                shiftS[i]+=13;

            }//end if (shiftS[i] >= 97 && shiftS[i] <= 109)

            else if(shiftS[i] >= 110 && shiftS[i] <= 122){

                shiftS[i]-=13;

            }//end else if (shiftS[i] >= 110 && shiftS[i] <= 122)

           
        }//end for (int i = 0; i<shiftS.length;i++)

        return new String(shiftS); //returns new / original string depending if changes could be made

    }//end method encrypt

    public static String decrypt(String s){

        s = s.toLowerCase();

        char [] shiftS = s.toCharArray();

        for (int i = 0; i<shiftS.length;i++)

        {

            if(shiftS[i] >= 97 && shiftS[i] <= 109)

            {

                shiftS[i]+=13;

            }//end if (shiftS[i] >= 97 && shiftS[i] <= 109)

            else if(shiftS[i] >= 110 && shiftS[i] <= 122){

                shiftS[i]-=13;

            }//end else if (shiftS[i] >= 110 && shiftS[i] <= 122)

           
        }//end for (int i = 0; i<shiftS.length;i++)

        return new String(shiftS); //returns new / original string depending if changes could be made

    }//end method decrypt

}

Files

ROT13.java 1.5 kB
Jun 04, 2022

Get Click to See (Rotation/Shift) 13 Cipher

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.