How to encode a text with Affine Cipher Using char array alphabet?

My assignment is basicly encoding a user entered text with affine cipher.

Affine cipher basicly takes a and b keywords and a text for encoding then encodes it using this formula y = A*x+B mod 26 for each letter of text. X = Letter, Y= Encoded Letter. mod26 is for 26 letters of the alphabet
My assignment is basicly encoding a user entered text(Turkish) with affine cipher.
Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string.h>
#include<locale.h>
 using namespace std;
string encryption(string message,int a, int b)
{
char alfabe[29]={'A','B','C','Ç','D','E','F','G','Ğ','H','I','İ','J','K','L','M','N','O','Ö','P','R','S','Ş','T','U','Ü','V','Y','Z'};
string encryptedMessage= "";
for (unsigned x = 0; x < message.length(); x++)
{
encryptedMessage = encryptedMessage + alphabet[(((a * (message[x])) + b) % 29)];
}
return encryptedMessage;
}

int main()
{
setlocale(LC_ALL, "Turkish");
int a,b;
    cout<<"Enter keyword a."<<endl;
    cin>>a;
    cout<<"Enter keyword b."<<endl;
    cin>>b;
    string text;

   cout<<"Enter the text you want to encrypt"<<endl;
   cin>>text;
   cout<<encryption(text,a,b);
}

But this program use ASCII characters and its English alphabet but i need to use Turkish Alphabet but since i can't use ASCII for that i created my own alphabet with array.
My question is basicly how can i implement this alphabet to my string encryption(string message,int a, int b) function ? I tried to use for loop for some lame algorithm like : For each latter in message(entered by user) if letters equal to char alphabet array pick them then create Word in a array called Word but i think its too lame since i also have to throw that array into that encryption function then encrypt it with a lot of for loops.Final version is the code i give you above but it also gives broken character error since its probably takes values then implements them as ASCII so can you help me with this ? NOTE:Sorry for my grammar mistakes.
Last edited on
Topic archived. No new replies allowed.