替换算法

发布于 2024-10-18 21:29:35 字数 63 浏览 10 评论 0原文

如何使用 C# 代码在 ASP.NET 中执行替换加密算法?

请为我提供示例代码语法......

How to perform substitution encryption algorithm in ASP.NET using C# code ?

Please do provide me with sample code syntax....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹梦到西洲 2024-10-25 21:29:35
StringBuilder encryptedBuilder = new Stringbuilder();

for(int i = 0; i < key.Length; i++) {
    char e = getCharFor(key[i]); // this does substitution - implement this
    encryptedBuilder.Append(e);
}

string encryptedString = encryptedBuilder.ToString();
StringBuilder encryptedBuilder = new Stringbuilder();

for(int i = 0; i < key.Length; i++) {
    char e = getCharFor(key[i]); // this does substitution - implement this
    encryptedBuilder.Append(e);
}

string encryptedString = encryptedBuilder.ToString();
梦里寻她 2024-10-25 21:29:35

实际上,ROT13 是 Caesar cipher 的变体,其思想是将纯文本的字母移动 N 个位置进一步在字母表中。 ROT13 或凯撒密码都不安全。为什么 ?

基本上,我们可以将加密强度定义为破解给定加密文本所需的工作量。那么我们应该怎么做才能打破这些呢? :

  • ROT13->我们只需将每个字符在字母表中向后移动 13 个位置即可。 (根本没有安全感)。
  • 凯撒密码 ->
    对于 N=1 到 26 执行:
        将每个字符在字母表中向后移动 N 个位置。
        如果有很多常见的英文单词(the, and, that,...) - 加密就被破解了。
    所以在凯撒案例中仍然需要 26 次迭代来破解加密文本的数量如此之小,以至于我们可以有把握地说凯撒密码也没有安全性。 (不过当然比ROT13好一点)。

如果您想要更有用的替代密码,请使用 Vigenere 密码。与 ROT13/Caesar 密码相反 - Vigenere 密码在加密操作中不使用 FIXED 字母表。 (它通过按所需顺序切换来使用多个字母表)。这就是为什么 Vigenere 比 ROT13/Caesar 更安全。 Vigenere 仍然是弱加密,与XOR 加密相当。维热内尔为什么弱?基本上是因为它容易受到频率分析的影响(当然,首先需要猜测/查找密钥长度)。
这是 vigenere C# 代码(以及 Caesar/ROT13)。

祝你好运!

Actually ROT13 is a variant of Caesar cipher which idea is to shift letter of plain-text by N positions further in the alphabet. Neither ROT13 or Caesar cipher is secure. Why ?

Basically one can define encryption strength as amount of work one needs to do for breaking given encrypted text. So what we should do for breaking these ? :

  • ROT13 -> we simply shift back each character by 13 positions in alphabet. (No security at all).
  • Caesar cipher ->
    for N=1 to 26 do:
        shift each character by N positions back in the alphabet.
        If a lot of common English words (the, and, that,...) - encryption is cracked.
    So in Caesar case still 26 iterations for cracking encrypted text is so small number that we can safely claim that Caesar cipher has no security also. (But of course it is a bit better than ROT13).

If you want a bit more useful substitution cipher- then use Vigenere cipher. Contrary to ROT13/Caesar ciphers - Vigenere cipher doesn't use FIXED alphabet in encryption operation. (It uses several alphabets by switching them in required order). That is why Vigenere is more secure than ROT13/Caesar. Still Vigenere is weak encryption and is comparable to XOR encryption. Why Vigenere is weak ? Basically because it is vulnerable to Frequency analysis (of course at first one needs to guess/find key length).
Here it is vigenere C# code (along with Caesar/ROT13).

good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文