Given a string, the task is to encrypt this string using ! and @ symbols, alternatively. While encrypting the message the encrypted format must repeat the symbol as many times as the letter position in Alphabetical order.
Input: string = "Ab" Output: !@@ Explanation: Position of 'A' in alphabetical order is 1 and in String is odd position so encrypted message will have 1 '!' Position of 'b' in alphabetical order is 2 and in String is even position so encrypted message will have 2 '@' Therefore, the output "!@@" Input: string = "CDE" Output: !!!@@@@!!!!!
Approach: This is a very basic and simple type of Encryption technique and can be done as follows:
- Get the character one by one from the String
- For each character, get the difference between the ASCII value of that character and ‘A'(if the character is a capital letter) or ‘a’ (if the letter is a small letter). This will be the number of times the encryption character is to be repeated.
- For the ith character of the string, if i is odd, the encryption character will be ‘!’ and if i is even, the encryption character will be ‘@’.
Below is the implementation of the above code:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Encrypt the given string with the following operations
- Encrypt a string into the Rovarspraket (The Robber Language)
- Encrypt a string by repeating i-th character i times
- Encrypt string with product of number of vowels and consonants in substring of size k
- Program to print all substrings of a given string
- Program to reverse words in a given string in C++
- Program for length of a string using recursion
- Program to extract words from a given String
- C++ Program to compare two string using pointers
- C Program to Check if a Given String is Palindrome
- Program to toggle all characters in a string
- Program to duplicate Vowels in String
- C++ program to check whether a String is a Pangram or not
- C++ Program to remove spaces from a string
- Program to remove vowels from a String
- Program for Reversed String Pattern
- C program to find the length of a string
- C program to copy string without using strcpy() function
- Program to reverse a string (Iterative and Recursive)
- Recursive program to replace all occurrences of pi with 3.14 in a given string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.