Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

caesar cipher java

//A Java Program to illustrate Caesar Cipher Technique
class CaesarCipher
{
    // Encrypts text using a shift od s
    public static StringBuffer encrypt(String text, int s)
    {
        StringBuffer result= new StringBuffer();
 
        for (int i=0; i<text.length(); i++)
        {
            if (Character.isUpperCase(text.charAt(i)))
            {
                char ch = (char)(((int)text.charAt(i) +
                                  s - 65) % 26 + 65);
                result.append(ch);
            }
            else
            {
                char ch = (char)(((int)text.charAt(i) +
                                  s - 97) % 26 + 97);
                result.append(ch);
            }
        }
        return result;
    }
 
    // Driver code
    public static void main(String[] args)
    {
        String text = "ATTACKATONCE";
        int s = 4;
        System.out.println("Text  : " + text);
        System.out.println("Shift : " + s);
        System.out.println("Cipher: " + encrypt(text, s));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java char to charsequence 
Java :: data java 
Java :: sorting char array in java 
Java :: java int to string 
Java :: region in android studio 
Java :: @data lombok 
Java :: java reverse linked list 
Java :: java for each 
Java :: How to efficiently find three largest numbers of array, in Java? 
Java :: android activity read intent extra 
Java :: java guid 
Java :: Fast Lookup of Java 
Java :: jframe set visibility 
Java :: android java get current time 
Java :: reflections java 
Java :: byte array to base64 string 
Java :: java foreach arraylist 
Java :: kotlin variable in string 
Java :: how to check the lines in a file java scanner 
Java :: java add button 
Java :: Java Stack class pop() method 
Java :: set password visible in android 
Java :: Get the last Friday of a month in Java 
Java :: 12 hours to 24 hours java 
Java :: how to get the smallest number in an array java 
Java :: how to solve Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
Java :: split string regex java 
Java :: java empty array 
Java :: java responseentity 
Java :: timestamp to date java 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =