-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gost28147 #2
base: develop
Are you sure you want to change the base?
Gost28147 #2
Conversation
return EXIT_FAILURE; | ||
} | ||
|
||
uint32_t* Key = (uint32_t*)malloc(8 * sizeof(uint32_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Уже хорошо, что не в цикле. Но зачем ты вообще делаешь динамическое выделение памяти? Почему нельзя просто объявить массив key[] = {0x0123,...}, тоже самое для subTable
software/gost28147/Gost28147.cpp
Outdated
n1 = *((uint32_t *)&blockin[0]); | ||
n2 = *((uint32_t *)&blockin[4]); | ||
|
||
// 32 ����� ������� ������ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
поправь кодировку файлы, чтобы комментарии были читабельными
|
||
void Gost28147_encode(uint8_t* blockin, uint8_t* blockout, uint32_t* Key, uint8_t** SubTable) | ||
{ | ||
uint8_t first_uint8_t, second_uint8_t, zam_symbol, n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Очень плохие имена переменных! Почитай вот это https://learn.javascript.ru/variable-names
n1 = SUM232; | ||
} | ||
|
||
if (k<24) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Может быть будет проще c = k % 8 ??? Одна строчка и никаких if. Чем меньше в коде условий, тем лучше
software/gost28147/Gost28147.cpp
Outdated
|
||
// ���������� ��������� | ||
uint8_t ind = 0; | ||
for (q = 0; q <= 3; q++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть такая замечательная функция как memcpy, но даже лучше обойтись без неё, потому что не будет инструкций на вызов подпрограммы (функции memcpy)
*((uint32_t*)(blockout)) = n1; *((uint32_t*)(blockout+4)) = n2;
blockout[ind++] = *((uint8_t *)&n2 + q); | ||
} | ||
|
||
void Gost28147_decode(uint8_t* blockin, uint8_t* blockout, uint32_t* Key, uint8_t** SubTable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У тебя до этого была хорошая идея, что кодирование и декодирование делалось одним методом, но оформил ты её плохо. На чистом языке Си это можно сделать так
где-нибудь сразу после #include в этом файле обяъвляешь прототип функции (обрати внимание на названия переменных и метода)
static void simpleReplace(uint8_t* in, uint8_t* out, uint32_t* key, uint8_t** subTable, uint8_t mode)
ключевое слово static в данном случае говорит, что метод simpleReplace используется только внутри этого файла и нигде больше в программе. Далее где-нибудь в этом файле пишешь тело функции. А твои методы decode, encode будут выглядеть так
void gost28147_encode(uint8_t* in, uint8_t* out, uint32_t* key, uint8_t** subTable)
{
simpleReplace(in,out,key,subTable,0);
}
void gost28147_decode(uint8_t* in, uint8_t* out, uint32_t* key, uint8_t** subTable)
{
simpleReplace(in,out,key,subTable,1);
}
No description provided.