# Caesar Cipher

### Problem Statement :

```Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b and c.

Original alphabet:      abcdefghijklmnopqrstuvwxyz
Alphabet rotated +3:    defghijklmnopqrstuvwxyzabc

Function Description

Complete the caesarCipher function in the editor below.

caesarCipher has the following parameter(s):

string s: cleartext
int k: the alphabet rotation factor

Returns

string: the encrypted string

Input Format

The first line contains the integer, n, the length of the unencrypted string.
The second line contains the unencrypted string, s.
The third line contains k, the number of letters to rotate the alphabet by.

Constraints

1  <=  n  <=  100
0  <=  k   <=  100
s is a valid ASCII string without any spaces.```

### Solution :

```                            ```Solution in C :

In   C++  :

#include <iostream>
#include <string>
using namespace std;

int main() {
int N = 0, K = 0;
string str, dummy;
cin >> N; getline(cin, dummy);
getline(cin, str);
cin >> K;
int len = str.length();
for (int i = 0; i < len; ++i)
{
if (65 <= str[i] && str[i] <= 90)
str[i] = char(65 + ((str[i] - 65) + K) % 26);
else if (97 <= str[i] && str[i] <= 122)
str[i] = char(97 + ((str[i] - 97) + K) % 26);
}
cout << str << endl;
return 0;
}

In   Java  :

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int len = s.nextInt(); s.nextLine();
String str = s.nextLine();
int shift = s.nextInt();

char sarr[] = str.toCharArray();
for (int i=0; i<sarr.length; i++) {
sarr[i] = cryptIt(sarr[i], shift);
}
System.out.println(new String(sarr));
}

public static char cryptIt(char c, int shift) {
if (!Character.isAlphabetic(c)) return c;
char base = 'A';
if (c >= 'a') base = 'a';
return (char)(((c - base + shift) % 26) + base);
}
}

In   C :

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

int n,i,j,k;
char ar[101];
unsigned char x;
scanf("%d",&n);
scanf("%s",ar);
scanf("%d",&k);
for(i=0;i<n;i++)
{
x=ar[i];
if(x>=97 && x<=122)
{
x=x+(k%26);
if(x>122)
{
x=96+(x-122);
}
ar[i]=x;
}
else if(x>=65 && x<=90)
{
x=x+(k%26);
if(x>90)
{
x=64+(x-90);
}
ar[i]=x;
}
}
printf("%s",ar);
return 0;
}

In Python3 :

def main():
l = input()
st = input()
s = int(input())
l_s = [chr(i) for i in range(ord('a'),ord('z')+1)]
l_b = [chr(i) for i in range(ord('A'),ord('Z')+1)]
cpy = ""
for i in st:
if i in l_s:
cpy += l_s[(l_s.index(i)+s)%26]
elif i in l_b:
cpy += l_b[(l_b.index(i)+s)%26]
else:
cpy += i
print (cpy)

if __name__ == "__main__":
main()```
```

## Find Merge Point of Two Lists

This challenge is part of a tutorial track by MyCodeSchool Given pointers to the head nodes of 2 linked lists that merge together at some point, find the node where the two lists merge. The merge point is where both lists point to the same node, i.e. they reference the same memory location. It is guaranteed that the two head nodes will be different, and neither will be NULL. If the lists share

## Inserting a Node Into a Sorted Doubly Linked List

Given a reference to the head of a doubly-linked list and an integer ,data , create a new DoublyLinkedListNode object having data value data and insert it at the proper location to maintain the sort. Example head refers to the list 1 <-> 2 <-> 4 - > NULL. data = 3 Return a reference to the new list: 1 <-> 2 <-> 4 - > NULL , Function Description Complete the sortedInsert function

## Reverse a doubly linked list

This challenge is part of a tutorial track by MyCodeSchool Given the pointer to the head node of a doubly linked list, reverse the order of the nodes in place. That is, change the next and prev pointers of the nodes so that the direction of the list is reversed. Return a reference to the head node of the reversed list. Note: The head node might be NULL to indicate that the list is empty.

## Tree: Preorder Traversal

Complete the preorder function in the editor below, which has 1 parameter: a pointer to the root of a binary tree. It must print the values in the tree's preorder traversal as a single line of space-separated values. Input Format Our test code passes the root node of a binary tree to the preOrder function. Constraints 1 <= Nodes in the tree <= 500 Output Format Print the tree's

## Tree: Postorder Traversal

Complete the postorder function in the editor below. It received 1 parameter: a pointer to the root of a binary tree. It must print the values in the tree's postorder traversal as a single line of space-separated values. Input Format Our test code passes the root node of a binary tree to the postorder function. Constraints 1 <= Nodes in the tree <= 500 Output Format Print the

## Tree: Inorder Traversal

In this challenge, you are required to implement inorder traversal of a tree. Complete the inorder function in your editor below, which has 1 parameter: a pointer to the root of a binary tree. It must print the values in the tree's inorder traversal as a single line of space-separated values. Input Format Our hidden tester code passes the root node of a binary tree to your \$inOrder* func