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:
- Encrypt the given string with the following operations
- Encrypt a string by repeating i-th character i times
- Encrypt a string into the Rovarspraket (The Robber Language)
- Encrypt string with product of number of vowels and consonants in substring of size k
- Program to extract words from a given String
- C program to find the length of a string
- Program to toggle all characters in a string
- Program to remove vowels from a String
- Program for length of a string using recursion
- C++ Program to remove spaces from a string
- Program for Reversed String Pattern
- C Program to Check if a Given String is Palindrome
- Program to print all substrings of a given string
- C++ Program to compare two string using pointers
- Program to duplicate Vowels in 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 firstname.lastname@example.org. 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.