Program of CaesarCipher
Have the function CaesarCipher (str, num) take the stx parameter and perform a Caesar Cipher shift on it using the num parameter as the shifting number. A Caesar Cipher works by shifting each letter in the string N places in the alphabet (in this case N will be num). Punctuation, spaces, and capitalization should remain intact. For example if the string is "Caesar Cipher and num is 2 the output should be "Ecguct Ekrjgt".
Examples:-
Input: "Hello" & num= 4
Output: Lipps
Input: "abc" & num=0
Output: abc
Program of CaesarCipher
The objective of the code is to perform a Caesar Cipher shift on it using the num parameter as the shifting number .
C++ Code:-
#include<bits/stdc++.h>
using namespace std;
string CaesarCipher(string str,int num)
{
string result="";
for(int i=0;i<str.length();i++)
{
if(isupper(str[i]))
{
//Ascii of A is 65
result+=char(int(str[i]+num-65)%26+65);
}
else if(islower(str[i]))
{
// Ascii of a is 97
result+=char(int(str[i]+num-97)%26+97);
}
else
result+=str[i];
}
return result;
}
int main()
{
string str;
int num;
getline(cin,str);
cin>>num;
cout<<CaesarCipher(str,num);
return 0;
}
Output:
Caesar Cipher
2
Ecguct Ekrjgt
Companies interview:-
- Swap adjacent characters
- Double the vowel characters
- Check valid parenthesis
- Print the characters with their frequencies
- Find closest value
- Word Count
- Program of CaesarCipher
- Program to find the perfect city
- Annual Day | Tech Mahindra coding question
- Find the number of pairs in the array whose sum is equal to a given target.
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
0 Comments