Decrypt a string according to given rules - GeeksforGeeks (2024)

#include <bits/stdc++.h>

using namespace std;

// Function for encryption

string encrypted_string(string strg)

{

string EncryptedString = { strg[0] };

for (int t = 1; t < strg.length(); t++) {

if (t % 2 == 1) {

EncryptedString.push_back(

strg[t]); // At odd position, append the

// next character

}

else {

EncryptedString.insert(

0, 1, strg[t]); // At Even position, prepend

// the next character

}

}

// print the resultant string

return EncryptedString;

}

// Function for decryption

string decrypted_string(string strg)

{

// Check the divisibility of length of string by 2

if (strg.length() % 2 != 0) {

string DecryptedString = { strg[0] };

for (int t = 1; t < strg.length(); t++) {

DecryptedString.push_back(

strg[strg.length() - 1

- t]); // First add the characters from

// the back

DecryptedString.push_back(

strg[t]); // from the front

}

reverse(

DecryptedString.begin(),

DecryptedString.end()); // Reverse the final

// string to get output

return DecryptedString;

}

else {

string reverse_strg = strg;

reverse(

reverse_strg.begin(),

reverse_strg

.end()); // In case of even length, reverse

// the given string first

string DecryptedString = { reverse_strg[0] };

// Looping over the reversed string

for (int t = 1; t < reverse_strg.length(); t++) {

DecryptedString.push_back(

reverse_strg[reverse_strg.length() - 1

- t]); // First add the

// characters from the

// back

DecryptedString.push_back(

reverse_strg[t]); // and then from the front

}

reverse(

DecryptedString.begin(),

DecryptedString.end()); // Reverse the final

// string to get output

return DecryptedString;

}

}

// Testing the algorithm with Driver Code

int main()

{

cout << encrypted_string("geeks") << endl;

cout << encrypted_string("geeksforgeeks") << endl;

cout << encrypted_string("strive") << endl;

cout << encrypted_string("vikaschitturi") << endl;

cout << encrypted_string("padmachitturi") << endl;

cout << encrypted_string("hackerrank") << endl;

cout << encrypted_string("hackerearth") << endl;

cout << encrypted_string("codechef") << endl;

cout << encrypted_string("IamVikas") << endl;

cout << encrypted_string("HelloHowareyou") << endl;

cout << encrypted_string("whatareyoudoing") << endl;

cout << decrypted_string("segek") << endl;

cout << decrypted_string("segosegekfrek") << endl;

cout << decrypted_string("vrstie") << endl;

cout << decrypted_string("iuthskviacitr") << endl;

cout << decrypted_string("iuthadpamcitr") << endl;

cout << decrypted_string("nrechakrak") << endl;

cout << decrypted_string("hreechakrat") << endl;

cout << decrypted_string(encrypted_string("IamVikas"))

<< endl;

cout << decrypted_string(

encrypted_string("HelloHowareyou"))

<< endl;

return 0;

}

Decrypt a string according to given rules - GeeksforGeeks (2024)
Top Articles
How Much Does Ballistic Glazing Cost?
Adult Disability Payment
Navicent Human Resources Phone Number
Craigslist Home Health Care Jobs
Palm Coast Permits Online
Craigslist Cars Augusta Ga
Robot or human?
What Happened To Dr Ray On Dr Pol
What is the surrender charge on life insurance?
Tcu Jaggaer
Help with Choosing Parts
Jellyfin Ps5
Costco Great Oaks Gas Price
2024 INFINITI Q50 Specs, Trims, Dimensions & Prices
Melissababy
Food Universe Near Me Circular
Aes Salt Lake City Showdown
Minnick Funeral Home West Point Nebraska
Brbl Barber Shop
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
BJ 이름 찾는다 꼭 도와줘라 | 짤방 | 일베저장소
Craig Woolard Net Worth
Gilchrist Verband - Lumedis - Ihre Schulterspezialisten
Urbfsdreamgirl
Hwy 57 Nursery Michie Tn
Reserve A Room Ucla
Miles City Montana Craigslist
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Plasma Donation Racine Wi
Abga Gestation Calculator
Ff14 Laws Order
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
How does paysafecard work? The only guide you need
Pill 44615 Orange
Personalised Handmade 50th, 60th, 70th, 80th Birthday Card, Sister, Mum, Friend | eBay
Craigslist Pets Huntsville Alabama
Troy Gamefarm Prices
Rochester Ny Missed Connections
Michael Jordan: A timeline of the NBA legend
M Life Insider
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
How Does The Common App Work? A Guide To The Common App
Casamba Mobile Login
Mississippi weather man flees studio during tornado - video
Chathuram Movie Download
Joey Gentile Lpsg
Sarahbustani Boobs
Canvas Elms Umd
The Bold and the Beautiful
3367164101
Craigslist Chautauqua Ny
Raley Scrubs - Midtown
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 5818

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.