Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions b64.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <string>
#include <sstream>
#include <iostream>
Expand Down
5 changes: 3 additions & 2 deletions encrypt.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once
#include "b64.h"
#include "vigenere.h"

std::string encrypt(std::string& msg, std::string& key) {
static std::string encrypt(std::string& msg, std::string& key) {
std::string b64_str = base64_encode(msg);
std::string vigenere_msg = encrypt_vigenere(b64_str, key);
// std::cout << vigenere_msg << std::endl;
return vigenere_msg;
}


std::string decrypt(std::string& encrypted_msg, std::string& key) {
static std::string decrypt(std::string& encrypted_msg, std::string& key) {
std::string newKey = extend_key(encrypted_msg, key);
std::string b64_encoded_str = decrypt_vigenere(encrypted_msg, newKey);
std::string b64_decode_str = base64_decode(b64_encoded_str);
Expand Down
11 changes: 6 additions & 5 deletions vigenere.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <stdio.h>
#include <string.h>
#include <string>
Expand All @@ -7,9 +8,9 @@

using namespace std;

std::string AVAILABLE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
static std::string AVAILABLE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";

int index(char c) {
static int index(char c) {
for(int ii = 0; ii < AVAILABLE_CHARS.size(); ii++) {
if(AVAILABLE_CHARS[ii] == c) {
// std::cout << ii << " " << c << std::endl;
Expand All @@ -20,7 +21,7 @@ int index(char c) {
}


std::string extend_key(std::string& msg, std::string& key) {
static std::string extend_key(std::string& msg, std::string& key) {
//generating new key
int msgLen = msg.size();
std::string newKey(msgLen, 'x');
Expand All @@ -36,7 +37,7 @@ std::string extend_key(std::string& msg, std::string& key) {
}


std::string encrypt_vigenere(std::string& msg, std::string& key) {
static std::string encrypt_vigenere(std::string& msg, std::string& key) {
int msgLen = msg.size(), keyLen = key.size(), i, j;
std::string encryptedMsg(msgLen, 'x');
// char newKey[msgLen], encryptedMsg[msgLen], decryptedMsg[msgLen];
Expand All @@ -57,7 +58,7 @@ std::string encrypt_vigenere(std::string& msg, std::string& key) {
return encryptedMsg;
}

std::string decrypt_vigenere(std::string& encryptedMsg, std::string& newKey) {
static std::string decrypt_vigenere(std::string& encryptedMsg, std::string& newKey) {
// decryption
int msgLen = encryptedMsg.size();
std::string decryptedMsg(msgLen, 'x');
Expand Down