Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Trying to do an affine cipher in c++

$
0
0
I'm in the process of writing an affine cipher code that uses the ax+b form, and I found it is 5x+8. I'm attaching my code. The comments are me commenting out what I was testing and what have you. I thought I was on the right track but then when I compile it, it comes up with three blocks on top of each other, with four numbers in each block? What is going on? I'm attaching a screen shot file of it since I can't copy and paste it. Here's the code too:
#include<iostream>
#include<string>
#include<cctype>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
        string answer;
        cout << "Enter a word: ";
        cin >> answer;
        int length = answer.length();
        for (int count = 0; count < length ; count++){
                if (isalpha(answer[count])){
                        answer[count] = tolower(answer[count]);
                        //for (unsigned s = 0; s < answer.length(); s++){
                                answer.at(count)= 5*count+8;
                                cout << answer.at(count) << endl;
                        }
                        //for (int i = 0; i < 25; i++){
                        //      if (answer[count] == 'z')
                        //              answer[count] == 'a';
                        //      else
                        //              answer[count]++;
                        //}
                }

        //cout << answer;

        //for (unsigned i = 0; i < answer.length();++i)
        //      cout << answer.at(i);
        //cout << answer.at(3) << endl; 
        //cin >> a;
        //a = toupper(a);
        //cout << a;

        return 0;

}




I want to know why it's showing the blocks. But also, maybe, if possible, some help, on printing out the letter in cipher code (5x+8) if I'm not doing it right?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>