Created
May 11, 2020 07:53
-
-
Save computingfreak/be8ee855c4e4b9443189467919ac7b0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.math.*; | |
import java.security.*; | |
import java.text.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.regex.*; | |
public class CaeserCipher { | |
static String caesarCipher(String s, int k) { | |
k=k%26; | |
String z=""; | |
for(int i=0;i<s.length();i++){ | |
char t=s.charAt(i); | |
int r=(int)t; | |
if (Character.isLetter(t) && Character.isLowerCase(t)){ | |
int p = 97+(r-97+k)%26; | |
System.out.println(t+","+r+","+p+","+(char)p); | |
z=z+(char)p; | |
} | |
else if(Character.isLetter(t) && Character.isUpperCase(t)){ | |
int q = 65+(r-65+k)%26; | |
System.out.println(t+","+r+","+q+","+(char)q); | |
z=z+(char)q; | |
} | |
else{ | |
z=z+t; | |
} | |
} | |
return z; | |
} | |
private static final Scanner scanner = new Scanner(System.in); | |
public static void main(String[] args) throws IOException { | |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); | |
int n = scanner.nextInt(); | |
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | |
String s = scanner.nextLine(); | |
int k = scanner.nextInt(); | |
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | |
String result = caesarCipher(s, k); | |
bufferedWriter.write(result); | |
bufferedWriter.newLine(); | |
bufferedWriter.close(); | |
scanner.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment