Я хочу сделать следующее:
Если у вас есть какая-либо буква, я хочу использовать ее код ascii для создания простого метода шифрования.
Например, если у меня есть буква «H», ее код ascii равен 72. Тогда шифрование будет (72 mod 60) +1 = 13. 13 будет «ключом», а зашифрованная буква будет быть просто 72 + ключ = 72 + 13 = 85.
Я думаю, что у меня есть что-то, но я получаю столкновения, и я пробовал несколько способов, но я все еще не могу справиться с ними. Вот мой код:
#include <stdio.h>
#include <stdlib.h>
typedef struct letter{
char letter;
int key;
char criptedLetter;
}letter;
int hash (int n);
int main() {
printf("\nEncript the alphabet with a hash table");
int i=0;
char n = 'A';
letter * alphabet = calloc(60, sizeof(letter));
letter x;
while(i<=25){
x.letter = n;
int asciiOriginalLetter = n;
int key;
key = hash(x.letter);
if(alphabet[key].key != 0){
do{
key++;
if(key == 60){
key = 0;
}
}while(alphabet[key].key != 0);
x.criptedLetter = (int)x.letter + key;
alphabet[key] = x;
}
else{
x.criptedLetter = (int)x.letter + key;
alphabet[key] = x;
}
i++;
n++;
}
for(i=0; i<60; i++){
printf("\nIn position %d there's letter %c with key %d and cripted letter %c", i, alphabet[i].letter, alphabet[i].key, alphabet[i].criptedLetter);
}
return 0;
}
int hash (int n){
int key;
key = (n % 60)+1;
return key;
}
Примечание: вчера я задал похожий вопрос, и некоторые из вас оказали потрясающую помощь, это новый код.