使用rot13编写加密文件的代码 [英] Write code to encrypt file using rot13

查看:135
本文介绍了使用rot13编写加密文件的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用rot13加密文件中的文本。有人可以帮我解释我需要翻译文本的代码吗?



我尝试了什么:



I am trying to encrypt text from a file using rot13. Can someone help me with the code I will need to translate the text?

What I have tried:

private void rotEncrypt() {
      StringBuilder result = new StringBuilder();
      foreach (char i in text.ToString()) {
          if (i >= 'a' && i <= 'm' || i >= 'A' && i <= 'M') {
              result.Append((char)((int)i + 13));
          }
          else if (i >= 'n' && i <= 'z' || i >= 'N' && i <= 'Z') {
              result.Append((char)((int)i - 13));
          }
          else {
              // Leave other characters unchanged
              result.Append(i);
          }

          // Output the resulting string
          lbxEncryption.Items.Add(result.ToString());

推荐答案

这段代码不是自治的,我们无法测试它。

使用调试器来确保问题在这里。

建议:不要乱用演员

This code is not autonomous, we have no way to test it.
Use the debugger to make sure the problem is here.
Advice: don't mess with casts
result.Append(i + 13);



就够了。



你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />
调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


is enough.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于使用rot13编写加密文件的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆