package ShiftCipher;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class ShiftCipher
{
static String cipher(String msg, int shift){
String s = "";
int len = msg.length();
for(int x = 0; x < len; x++)
{
char c = (char)(msg.charAt(x) + shift);
if (c > 'z')
s += (char)(msg.charAt(x) - (26-shift));
else
s += (char)(msg.charAt(x) + shift); } return s;}
public static void main( String args[] )
{
String s1=JOptionPane.showInputDialog("Enter Value");
for (int i=1;i<=26;i++){
System.out.println("For k="+i +"\t\t"+cipher(s1, i));
} }}
No comments:
Post a Comment