C++内联汇编有什么问题吗?
首先,请使用简单的单词,因为我的英语不太好;)
现在的问题是:
我想编写一个程序,可以使用简单的凯撒算法加密我的文本。这意味着字母字符成为字母表中较晚的字符,但我的程序不会从 Z 之后的字母表开头开始。现在的代码:
void Entschlüsseln(char Text[50], int Schlüssel)
{
char Entschlüsselt[sizeof(Text)];
for (int x = 0; x < sizeof(Text)-1; x++)
{
Entschlüsselt[x] = '\0';
}
char Zeichen;
for (int i = 0; i < sizeof(Text)-1; i++)
{
if (Text[i] != '\0')
{
Zeichen = Text[i];
for (int j = 0; j < Schlüssel; j++)
{
_asm
{
mov al, Zeichen
cmp al, 90
jb Großbuchstabe
mov al, Zeichen
sub al, 32
mov Zeichen, al
Großbuchstabe:
inc Zeichen
mov al, Zeichen
cmp al, 90
ja Anfang_Alphabet
jmp Ende
Anfang_Alphabet:
mov Zeichen, 65
Ende:
}
}
Entschlüsselt[i] = Zeichen;
}
}
cout << endl << Entschlüsselt;
}
我希望它没问题,你可以帮助我
First please use easy words, as i'm not really good in english ;)
And now the problem:
I wanted to code a program which can encrypt a text of mine with an easy Caesar algorithm. That means that the alphabetic character becomes a later character in the alphabet, but my program does not begin at the beginning of the alphabet after Z. Now the code:
void Entschlüsseln(char Text[50], int Schlüssel)
{
char Entschlüsselt[sizeof(Text)];
for (int x = 0; x < sizeof(Text)-1; x++)
{
Entschlüsselt[x] = '\0';
}
char Zeichen;
for (int i = 0; i < sizeof(Text)-1; i++)
{
if (Text[i] != '\0')
{
Zeichen = Text[i];
for (int j = 0; j < Schlüssel; j++)
{
_asm
{
mov al, Zeichen
cmp al, 90
jb Großbuchstabe
mov al, Zeichen
sub al, 32
mov Zeichen, al
Großbuchstabe:
inc Zeichen
mov al, Zeichen
cmp al, 90
ja Anfang_Alphabet
jmp Ende
Anfang_Alphabet:
mov Zeichen, 65
Ende:
}
}
Entschlüsselt[i] = Zeichen;
}
}
cout << endl << Entschlüsselt;
}
i hope it's ok and you can help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在纯 C++ 中更容易实现,无需汇编。
This would be much easier to implement in pure C++, without assembly.
也许您只想更改字符(如果它确实是字母),以便保留空格和其他字符。而且您使用的是 C++,因此使用
std::string
而不是char[]
更容易。只要尝试理解这段代码,应该是可以的。
Probably you only want to change the character if it is really a letter, so that space and other characters stay. And you are using C++, therefore it is easier to work with a
std::string
instead of achar[]
.Just try to understand this code, it should be possible.
我认为错误的代码是这一行:
由于 90(在 ASCII 中是
Z
)是 Großbuchstabe,因此您不应该从中减去 32。做到:I think the wrong code is this line:
Since 90 (which in ASCII is a
Z
) is a Großbuchstabe, you should not subtract 32 from it. Make it: