-
Notifications
You must be signed in to change notification settings - Fork 2
/
Caesar-Cipher.cpp
50 lines (47 loc) · 1.47 KB
/
Caesar-Cipher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
/**
* @file Class realize Caesar encryption metods.
* @class caesarCipher
* @author Full_droper <full_droper@pm.me>
* @version 0.0.1
*/
class CaesarCipher {
public:
/**
* Encode input data by Caesar Cipher.
* @name encode
* @param {string} rawData - raw data for encode.
* @param {number} key - (default 1) count of shift.
* @return {string} The encoded by Caesar Cipher data
*/
string encode(string rawData,int key){
char data[rawData.length() + 1];
strcpy(data, rawData.c_str());
if(key < 1) key = 1;
std:string result = "";
for (int i = 0 ; i < ( sizeof(data) / sizeof(data[0]) - 1); i++) {
result += (char) (( (int) data[i] ) + key);
}
return result;
}
/**
* Decode input data by Caesar Cipher.
* @name encode
* @param {string} rawData - raw data for encode.
* @param {number} key - (default 1) count of shift.
* @return {string} The decoded by Caesar Cipher data
*/
string decode(string rawData,int key){
char data[rawData.length() + 1];
strcpy(data, rawData.c_str());
if(key < 1) key = 1;
std:string result = "";
for (int i = 0 ; i < ( sizeof(data) / sizeof(data[0]) - 1 ); i++) {
result += (char) (( (int) data[i] ) - key);
}
return result;
}
};