Vote count:
0
I'm kinda a newbie to c++...had the class for about a month or so... Anywho, we are doing this final project where we have to make an encryption/ decryption program using the hill cipher method. I've run into a slight problem where when I am trying to return the numbers from the function, it displays symbols instead of the actual numbers. The function itself, however, works correctly. Even though this is homework/classwork, the teacher is allowing us to use online sources and external help, since, as I previously said, we have only been programming for a month or so. Any and all help would be greatly appreciated!!
#define NOMINMAX
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <windows.h>
#include <Windows.h>
#include <chrono>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int random1()
{
unsigned long long int xRan;
srand(time(NULL));
again:
xRan = rand() * 319 / 43 * 16 * 333 % 9999 + 1;
if (xRan <= 0)
goto again;
return xRan;
}
int random2()
{
unsigned long long int xRan;
srand(time(NULL));
again:
xRan = rand() * 319 * 43 / 16 * 321 % 9999 + 1;
if (xRan <= 0)
goto again;
return xRan;
}
int random3()
{
unsigned long long int xRan;
srand(time(NULL));
again:
xRan = rand() * 319 / 43 / 16 * 2 % 9999 + 1;
if (xRan <= 0)
goto again;
return xRan;
}
int convert(char conv)
{
return (int)conv-87;
}
int matrixMult(double q, double w, double e)
{
int i, j, k, count = 0, total = 0;
double a, s, z, x, c, v, b, n, m;
a = random1();
s = random2();
z = random3();
x = random1();
c = random2();
v = random3();
b = random1();
n = random2();
m = random3();
int A[1][3] = { q, w, e };
int B[3][3] = {
{ a, s, z },
{ x, c, v },
{ b, n, m }
};
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
{
for (k = 0; k < 3; ++k)
total += A[i][k] * B[k][j];
cout << setw(5) << total << ' ';
++count;
if (count % 3 == 0)
cout << endl;
total = 0;
}
}
return 0;
}
int main()
{
string again = "y";
cout << "Would you like to encrypt or decrypt?(e/d) " << endl;
string ende;
cin >> ende;
if (ende == "e")
{
cout << "Please enter a name for the message: " << endl;
string file;
cin >> file;
file += ".txt";
ofstream encrypt;
encrypt.open(file);
string message;
cout << "Please enter the message you would like to encrypt: " << endl << endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
getline(cin, message);
//int length = message.size();
char converted[9999];
for (int i = 0; i < message.length(); ++i)
{
converted[i] = convert(message[i]);
cout << converted[i] << endl;
}
encrypt.close();
cout << "Your message has been encrypted.\nPlease check " << file << " for the encrypted message and key" << endl;
}
if (ende == "d")
{
cout << "0";
}
return 0;
}
asked 44 secs ago
How to convert letters in string to numbers - C++
Aucun commentaire:
Enregistrer un commentaire