Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********
- -*- Made by VoxelPixel
- -*- For YouTube Tutorial
- -*- https://github.com/VoxelPixel
- -*- Support me on Patreon: https://www.patreon.com/voxelpixel
- *********/
- #include <iostream>
- #include <string>
- using namespace std;
- //we'll be using ASCII in this
- string schlüssel(int wahl, string dat, int schlüssel)
- {
- int choice;
- /*
- cout << "1. Encryption" << endl << "2. Decryption" << endl << "Enter choice(1,2): ";
- cin >> choice;
- cin.ignore();
- */
- choice = wahl;
- if (choice == 1) {
- // encryption
- string msg;
- /*cout << "Message can only be alphabetic" << endl;
- cout << "Enter message: ";
- getline(cin, msg);
- msg = dat;
- */
- int key;
- /*
- cout << "Enter key (0-25): ";
- cin >> key;
- cin.ignore();
- */
- key = schlüssel;
- string encryptedText = msg;
- for (int i = 0; i < msg.size(); i++) {
- if (msg[i] == 32) {
- continue; //32 is ASCII of space character, we will ignore it
- }
- else {
- if ((msg[i] + key) > 122) {
- //after lowercase z move back to a, z's ASCII is 122
- int temp = (msg[i] + key) - 122;
- encryptedText[i] = 96 + temp;
- }
- else if (msg[i] + key > 90 && msg[i] <= 96) {
- //after uppercase Z move back to A, 90 is Z's ASCII
- int temp = (msg[i] + key) - 90;
- encryptedText[i] = 64 + temp;
- }
- else {
- //in case of characters being in between A-Z & a-z
- encryptedText[i] += key;
- }
- } //if
- } // for
- //cout << "Encrypted Message: " << encryptedText;
- return encryptedText;
- }
- else if (choice == 2) {
- //decryption
- string encpMsg;
- /*cout << "Message can only be alphabetic" << endl;
- cout << "Enter encrypted text: ";
- getline(cin, encpMsg);
- */
- encpMsg = dat;
- int dcyptKey;
- /*cout << "Enter key (0-25): ";
- cin >> dcyptKey;
- cin.ignore();
- */
- dcyptKey = schlüssel;
- string decryptedText = encpMsg;
- for (int i = 0; i < encpMsg.size(); i++) {
- if (encpMsg[i] == 32) {
- continue; //ignoring space
- }
- else {
- if ((encpMsg[i] - dcyptKey) < 97 && (encpMsg[i] - dcyptKey) > 90) {
- int temp = (encpMsg[i] - dcyptKey) + 26;
- decryptedText[i] = temp;
- }
- else if ((encpMsg[i] - dcyptKey) < 65) {
- int temp = (encpMsg[i] - dcyptKey) + 26;
- decryptedText[i] = temp;
- }
- else {
- decryptedText[i] = encpMsg[i] - dcyptKey;
- }
- }
- }
- // cout << "Decrypted Message: " << decryptedText << endl;
- return decryptedText;
- }
- else {
- cout << "Invalid choice";
- }
- }
- int arr[26];
- void buchzähler(string dat, int max)
- {
- string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- //int lanalp = sizeof(alp) / sizeof(string);
- //int laenge = sizeof(dat) / sizeof(string);
- //cout << lanalp << " " <<laenge << endl;
- for (int i = 0; i < max; ++i)
- {
- for (int z = 0; z < 26; ++z)
- {
- if (dat[i] == alp[z])
- arr[z] += 1;
- }
- }
- }
- int main()
- {
- /* for (int i = 1; i <= 23; ++i)
- {
- string temp = schlüssel(2, "QNFRVAMVTRVAFPUEVSGYVPUTRFVPUREGRCBEGENRGPNRFNEFQNFMHYROMRV", i);
- cout << i << " : " << temp << endl;
- }
- */
- buchzähler("QNFRVAMVTRVAFPUEVSGYVPUTRFVPUREGRCBEGENRGPNRFNEFQNFMHYROMRV", 59);
- buchzähler("GRARAGFGNAQVFGNHSZHRAMRAHROREYVRSREGQVRVAFRVARZYRGMGRAYRORA", 59);
- buchzähler("FWNUETRCENRTGJHEQRAFVRMRVTRARVARUNTRERCREFBAZVGUBUREFGVEAHA", 59);
- buchzähler("QYNATRZSNYGVTRZUNYFNHSQRETEHAQYNTRQREZHRAMNOOVYQHATRAJHEQRR", 59);
- buchzähler("VAVAGHFPHYHZTRSHAQRAREWRGMGVAGHEVAORSVAQYVPUREXBCSNHFXNYXFG", 59);
- buchzähler("RVANYFMRVGTRABRFFVFPURFCBEGENRGPNRFNEFVQRAGVSVMVREGCBFGHZRQ", 59);
- buchzähler("NEFGRYYHATRASVAQRAFVPUJVRQREHZNHSZHRAMRAQRARARVAXBCSVZINGVX", 59);
- buchzähler("NARAGFCEVPUGQNFCBEGENRGVFGQRHGYVPUVQRNYVFVREGRENYFQVRMHYROM", 59);
- buchzähler("RVGRARAGFGNAQRARAQVRVQRNYVFVREHATQREQNEFGRYYHATQRFQVIHFVHYV", 59);
- buchzähler("HFFRGMGRFVPUVANHTHFGRVFPUREMRVGSBEGRVTRAFGNRAQVTVFGRVAJBUYV", 59);
- buchzähler("ANRTLCGRARAGFGNAQRARECBEGENRGXBCSNHFTEHRAFPUVRSREVAQRENAGVX", 59);
- buchzähler("RAFNZZYHATOREYVA", 16);
- string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- int stan[26] = {6,2,2,5,17,2,3,5,8,1,1,3,2,10,2,1,1,7,7,6,4,1,1,1,1,1};
- //int temp = 0;
- double res = 0.0;
- for (int i = 0; i < 26; ++i)
- {
- double temp = (double)arr[i] / 6.65;
- //temp += arr[i];
- res += temp;
- cout << alp[i] << ": " << temp << "%" <<" Durchschnitt Standard : " << stan[i] <<"%"<< endl;
- }
- cout << res << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement