We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01f0fcf commit a577ce0Copy full SHA for a577ce0
1 file changed
Caesar Cipher.java
@@ -0,0 +1,35 @@
1
+class CaesarCipher
2
+{
3
+ public static StringBuffer encrypt(String text, int s)
4
+ {
5
+ StringBuffer result= new StringBuffer();
6
+
7
+ for (int i=0; i<text.length(); i++)
8
9
+ if (Character.isUpperCase(text.charAt(i)))
10
11
+ char ch = (char)(((int)text.charAt(i) +
12
+ s - 65) % 26 + 65);
13
+ result.append(ch);
14
+ }
15
+ else
16
17
18
+ s - 97) % 26 + 97);
19
20
21
22
+ return result;
23
24
25
26
27
+ public static void main(String[] args)
28
29
+ String text = "ATTACKATONCE";
30
+ int s = 4;
31
+ System.out.println("Text : " + text);
32
+ System.out.println("Shift : " + s);
33
+ System.out.println("Cipher: " + encrypt(text, s));
34
35
+}
0 commit comments