A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/de/db6/a1z26__cipher_8cpp_source.html below:

TheAlgorithms/C++: ciphers/a1z26_cipher.cpp Source File

Go to the documentation of this file. 33

std::map<uint8_t, char> a1z26_decrypt_map = {

34

{1,

'a'

}, {2,

'b'

}, {3,

'c'

}, {4,

'd'

}, {5,

'e'

}, {6,

'f'

}, {7,

'g'

},

35

{8,

'h'

}, {9,

'i'

}, {10,

'j'

}, {11,

'k'

}, {12,

'l'

}, {13,

'm'

}, {14,

'n'

},

36

{15,

'o'

}, {16,

'p'

}, {17,

'q'

}, {18,

'r'

}, {19,

's'

}, {20,

't'

}, {21,

'u'

},

37

{22,

'v'

}, {23,

'w'

}, {24,

'x'

}, {25,

'y'

}, {26,

'z'

},

40

std::map<char, uint8_t> a1z26_encrypt_map = {

41

{

'a'

, 1}, {

'b'

, 2}, {

'c'

, 3}, {

'd'

, 4}, {

'e'

, 5}, {

'f'

, 6}, {

'g'

, 7},

42

{

'h'

, 8}, {

'i'

, 9}, {

'j'

, 10}, {

'k'

, 11}, {

'l'

, 12}, {

'm'

, 13}, {

'n'

, 14},

43

{

'o'

, 15}, {

'p'

, 16}, {

'q'

, 17}, {

'r'

, 18}, {

's'

, 19}, {

't'

, 20}, {

'u'

, 21},

44

{

'v'

, 22}, {

'w'

, 23}, {

'x'

, 24}, {

'y'

, 25}, {

'z'

, 26}};

53

std::transform(text.begin(), text.end(), text.begin(),

55

std::replace(text.begin(), text.end(),

':'

,

' '

);

56 for

(

char

letter : text) {

58

result += std::to_string(

59

a1z26_encrypt_map[letter]);

78

std::string

decrypt

(

const

std::string& text,

bool

bReturnUppercase =

false

) {

82

std::vector<std::string> word_array;

83

std::stringstream sstream(text);

85 while

(sstream >> word) {

86

word_array.push_back(word);

89 for

(

auto

& i : word_array) {

90

std::replace(i.begin(), i.end(),

'-'

,

' '

);

91

std::vector<std::string> text_array;

93

std::stringstream ss(i);

95 while

(ss >> res_text) {

96

text_array.push_back(res_text);

99 for

(

auto

& i : text_array) {

100

result += a1z26_decrypt_map[stoi(i)];

107 if

(bReturnUppercase) {

108

std::transform(result.begin(), result.end(), result.begin(), ::toupper);

122

std::string input =

"Hello World"

;

123

std::string expected =

"8-5-12-12-15 23-15-18-12-4"

;

126

std::cout <<

"Input: "

<< input << std::endl;

127

std::cout <<

"Expected: "

<< expected << std::endl;

128

std::cout <<

"Output: "

<< output << std::endl;

129

assert(output == expected);

130

std::cout <<

"TEST PASSED"

;

133

input =

"12-15-23-5-18-3-1-19-5"

;

134

expected =

"lowercase"

;

137

std::cout <<

"Input: "

<< input << std::endl;

138

std::cout <<

"Expected: "

<< expected << std::endl;

139

std::cout <<

"Output: "

<< output << std::endl;

140

assert(output == expected);

141

std::cout <<

"TEST PASSED"

;

144

input =

"21-16-16-5-18-3-1-19-5"

;

145

expected =

"UPPERCASE"

;

148

std::cout <<

"Input: "

<< input << std::endl;

149

std::cout <<

"Expected: "

<< expected << std::endl;

150

std::cout <<

"Output: "

<< output << std::endl;

151

assert(output == expected);

152

std::cout <<

"TEST PASSED"

;

std::string decrypt(const std::string &text, bool bReturnUppercase=false)

a1z26 decryption implementation

std::string encrypt(std::string text)

a1z26 encryption implementation

static void test()

Self-test implementations.

int main()

Main function.

Functions for A1Z26 encryption and decryption implementation.

Algorithms for encryption and decryption.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4