我的代码有什么问题? [英] what is wrong in my code?

查看:67
本文介绍了我的代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用执行模块化算术的函数(modexp)加密文件.但是我没有一种正确的方法来逐字符读取char,然后对该char执行一些算术(modexp),然后将加密的聊天记录写入新文件.
我已经写了这样的代码.

I''m trying to encrypt a file with a function(modexp) which does modular arithmetic. but I''m nor getting a proper way to read char by char and then do some arithmetic(modexp) on that char, then encrypted chat should be written to a new file.
I have written my code like this.

private void btnSubmit_Click(object sender, EventArgs e)
{

        FileStream fr = new FileStream(textBox6.Text, FileMode.Open, FileAccess.Read);
        try
        {
            MessageBox.Show("Encryption Started");
            FileStream fw = new FileStream(textBox7.Text, FileMode.Create, FileAccess.Write);
            byte[] buffer = new byte[1];
            while (fr.Position != fr.Length)
            {
                int m = fr.Read(buffer, 0, buffer.Length);
               string m1 = modexp(m.ToString().Trim(), textBox4.Text.Trim(), textBox3.Text.Trim());
               fw.Write(buffer, 0, Convert.ToInt32(m1));

            }
            fw.Flush();
            fr.Close();
            fw.Close();
            MessageBox.Show("Encryption Completed");

        }
        catch(Exception ex)
        {
            MessageBox.Show("File creation Error" + ex, "Implementation of RSA");
        }

  }


请帮帮我.

提前谢谢.
Ganesh.


Please help me.

Thanks in advance.
Ganesh.

推荐答案

我认为问题是modeexp.您需要显示其代码.但是看,它接受三个字符串,第一个参数不是字节,而是字符串.它没有对这个字节进行加密(这没有什么意义,但是假设您需要它),而是尝试对某些字符串进行加密,这只是该字节的可读形式.不,它不会加密此字节!我猜想您需要读取一个字符串中的文件,然后立即将其传递给modexp.

但是,我不信任此modexp.如果确实是一种正确的加密方法,它将接受字节数组作为第一个参数,而不是字符串.如果该方法将字符串参数转换为数字值,那么……很好,我什至不想讨论它.

现在,您为什么决定可以将模块化算术"用作一种真正的加密方法.好吧,这很荒谬,不使用加密会更好.为什么在地球上您将所有这些称为RSA ?! RSA是完全不同且严肃的事情,已在.NET中完全实现,请参见System.Security.Cryptography.RSASystem.Security.Cryptography.RSACryptoServiceProvider

—SA
I think the problem is modeexp. You need to show its code. But look, it accepts three strings, first argument is not byte, but strings. Instead of encrypting this one byte (which would make little sense, but let''s assume you need it), it tries to encrypt some string, which is just a human-readable representation of this byte. No, it won''t encrypt this byte! I can guess you need to read the file in one string and pass it to modexp at once.

However, I don''t trust this modexp. It if really was a correct encryption method, it would accepts array of byte as a first parameter, not a string. If the method converts a string parameter into something numeric this is… well, I don''t even want to discuss it.

Now, why did you decide that "modular arithmetic" can be used as a real encryption method. Well, this is ridiculous, using no encryption is better. And why on Earth would you call all that RSA?!! RSA is a completely different and serious thing, fully implemented in .NET, see System.Security.Cryptography.RSA, System.Security.Cryptography.RSACryptoServiceProvider

—SA


这篇关于我的代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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