Bifid cipher: Difference between revisions

m
Small improvement to code.
m (Correct minor error.)
m (Small improvement to code.)
Line 211:
#include <iostream>
#include <stdexcept>
#include <stringstring_view>
#include <unordered_map>
#include <vector>
Line 219:
class Bifid {
public:
Bifid(const int32_t n, const std::string&string_view text) {
if ( text.length() != n * n ) {
throw new std::invalid_argument("Incorrect length of text");
Line 246:
}
 
std::string encrypt(const std::string&string_view text) {
std::vector<int32_t> row_one, row_two;
for ( const char& ch : text ) {
Line 262:
}
 
std::string decrypt(const std::string&string_view text) {
std::vector<int32_t> row;
for ( const char& ch : text ) {
Line 281:
 
void display() const {
for ( const std::vector<char>& row : grid ) {
for ( const char& ch : row ) {
std::cout << ch << " ";
Line 293:
};
 
void runTest(Bifid& bifid, std::stringstring_view message) {
std::cout << "Using Polybius square:" << std::endl;
bifid.display();
Line 305:
 
int main() {
const std::stringstring_view message1 = "ATTACKATDAWN";
const std::stringstring_view message2 = "FLEEATONCE";
const std::stringstring_view message3 = "THEINVASIONWILLSTARTONTHEFIRSTOFJANUARY";
 
Bifid bifid1(5, "ABCDEFGHIKLMNOPQRSTUVWXYZ");
871

edits