Given encrypted string str, the task is to decrypt the given string when the encryption rules are as follows:
- Start with the first character of the original string.
- In every odd step, append the next character to it.
- In every even step, prepend the next character to the encrypted string so far.
For example, if str = “geeks” then the encrypted string will be,
g -> ge -> ege -> egek -> segek
Input: str = “segosegekfrek”
Input: str = “vrstie”
Approach: The steps that are given to encrypt the string can be followed in reverse order to obtain the original string. There will be two conditions to obtain the original string:
- If the string is of odd length, in odd step add the characters from the back in the resultant string, else add from the front.
- If the string is of even length, in odd step add characters from the front and add characters from back in even step.
The reverse of the resultant string thus obtained is the original string which was encrypted.
Below is the implementation of the above approach:
Below is Python’s implementation.
- Decrypt the String according to given algorithm
- Decrypt a string encrypted by repeating i-th character i times
- Check a given sentence for a given set of simple grammer rules
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Reverse the substrings of the given String according to the given Array of indices
- Change the given string according to the given conditions
- Sort a string according to the order defined by another string
- Find the last remaining Character in the Binary String according to the given conditions
- Encryption and Decryption of String according to given technique
- Rearrange a string according to the given indices
- Expand the string according to the given conditions
- Reverse substrings of given string according to specified array indices
- Sort an array of strings according to string lengths
- Reverse String according to the number of words
- Sort the array of strings according to alphabetical order defined by another string
- Sort an array of strings according to string lengths using Map
- Sort a string according to the frequency of characters
- Remove duplicates from string keeping the order according to last occurrences
- Check whether two strings are equivalent or not according to given condition
- Minimize the sum of the array according the given condition
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.