problem with encription program

hello
i have a problem with encripting a string.
the encription method is called hill cipher
the functions ToNum and ToChar are excluded because they just convert from a character to a number(a-1,b-2...)and from number to character
now the problem i have is with printing out the encripted code
for example
if the encription matrix is 1 2
3 4
and the entered letters are e and f
it should encript e and f as q and k
but instead it prints out random garbadge.
if anything about my question is unclear(because honestly im so confused i can hardly think) feel free to ask
i think the problem is in the last for loop in main
thanks in advance :)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
int ime_det_2x2 (int a[2][2], int b[2][1]);
int ToNum(char x);
int ToChar(int x);

int main (){
       string TextEncode;
    int a[2][2];
    int b[2][1];
    for (int brojach=0; brojach<2; brojach++){
for(int i=0;i<2;i++){
cout<<"vnesi determinanta na mesto"<<brojach+1<<i+1<<endl;
cin>>a[brojach][i];
}
}


cin>>TextEncode;


for(int i=0;i<=TextEncode.length();i++){

char p=TextEncode[i];
char q=TextEncode[i+1];

b[0][0]=ToNum(p);
b[1][0]=ToNum(q);


ime_det_2x2(a,b);
}
}




 int ToNum(char x){

 int ime_det_2x2 (int a[2][2], int b[2][1])
{
 int prv_broj, vtor_broj;
prv_broj=((a[0][0]*b[0][0])+(a[0][1]*b[1][0]))%26;
vtor_broj=((a[1][0]*b[0][0])+(a[1][1]*b[1][0]))%26;
char k;
char c;
k=ToChar(prv_broj);
c=ToChar(vtor_broj);

cout<<k;
cout<<c;
}

 int ToChar(int x ){

Topic archived. No new replies allowed.