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 string with product of number of vowels and consonants in substring of size k
- Encrypt a string into the Rovarspraket (The Robber Language)
- Encrypt a string by repeating i-th character i times
- Encrypt the given string with the following operations
- C program to copy string without using strcpy() function
- Python program to count number of vowels using sets in given string
- C++ Program to compare two string using pointers
- C program to print the length of a String using %n format specifier
- Program for length of a string using recursion
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Program to find the largest and smallest ASCII valued characters in a string
- Program to find Smallest and Largest Word in a String
- Program to count vowels in a string (Iterative and Recursive)
- Program to reverse a string (Iterative and Recursive)
- C program to count number of vowels and consonants in a String
- Program to count vowels, consonant, digits and special characters in string.
- Program to check if first and the last characters of string are equal
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- Check if a string can be converted to another string by replacing vowels and consonants
- Find the longest sub-string which is prefix, suffix and also present inside the 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.