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/d6/d2c/caesar__cipher_8cpp_source.html below:

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

Go to the documentation of this file. 43 inline char

get_char(

const int

x) {

53 inline int

get_value(

const char

c) {

65

std::string

encrypt

(

const

std::string &text,

const int

&shift) {

66

std::string encrypted_text =

""

;

67 for

(

char

c : text) {

68 int

place_value = get_value(c);

69

place_value = (place_value + shift) % 26;

70 char

new_char = get_char(place_value);

71

encrypted_text += new_char;

73 return

encrypted_text;

81

std::string

decrypt

(

const

std::string &text,

const int

&shift) {

82

std::string decrypted_text =

""

;

83 for

(

char

c : text) {

84 int

place_value = get_value(c);

85

place_value = (place_value - shift) % 26;

86 if

(place_value < 0) {

87

place_value = place_value + 26;

89 char

new_char = get_char(place_value);

90

decrypted_text += new_char;

92 return

decrypted_text;

102

std::string text1 =

"ALANTURING"

;

105

assert(text1 == decrypted1);

106

std::cout <<

"Original text : "

<< text1;

107

std::cout <<

" , Encrypted text (with shift = 21) : "

<< encrypted1;

108

std::cout <<

" , Decrypted text : "

<< decrypted1 << std::endl;

110

std::string text2 =

"HELLOWORLD"

;

113

assert(text2 == decrypted2);

114

std::cout <<

"Original text : "

<< text2;

115

std::cout <<

" , Encrypted text (with shift = 1729) : "

<< encrypted2;

116

std::cout <<

" , Decrypted text : "

<< decrypted2 << std::endl;

std::string decrypt(const std::string &text, const int &shift)

std::string encrypt(const std::string &text, const int &shift)

Functions for Caesar cipher algorithm.

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