Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,48 @@
* @author Kanahaiya Gupta
*
*/
public class CaesarCipher {
public static void main(String[] args) {
public class Solutions
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int n = sc.nextInt();
String s = sc.next();
int K = sc.nextInt();
String passwd=caeserCipher(s,K);
System.out.println(passwd);
}
public static String caeserCipher(String s,int K)
{
K = K % 26;
int N=s.length();
String passwd = "";
for (int i = 0; i < N; i++) {
for (int i = 0; i < N; i++)
{
int ch = s.charAt(i);
int t = (ch + K);

if (ch >= 97 && ch <= 122) {
if (t > 122) {
if (ch >= 97 && ch <= 122)
{
if (t > 122)
{
t = 96 + (t - 122);
}
passwd += (char) (t);
} else if (ch >= 65 && ch <= 90) {
if (t > 90) {
}
else if (ch >= 65 && ch <= 90)
{
if (t > 90)
{
t = 64 + (t - 90);
}
passwd += (char) (t);
} else {
}
else
{
passwd += (char) ch;
}
}
System.out.println(passwd);
sc.close();
return passwd;
}
}