当前位置:编程学习 > C#/ASP.NET >>

拿1000个异或码字节替换文件的前1000个字节?!

读取一个文件的前1000个字节,做异或处理,之后拿异或处理得到的1000个字节替换文件的前1000个字节,并把文件保存。



谁能帮帮我,

异或是不是只能针对字节操作,(在进行简单异或加密的时候),

怎么才能仅仅读取一个文件的前1000个字节,?


之后如何拿1000个字节去替换文件的前1000个字节,并保存呢?! --------------------编程问答-------------------- ?ddddddddddd --------------------编程问答-------------------- 将得到得新字节数组拼上原来得从1001开始得数组,在写进文件里 --------------------编程问答--------------------
引用楼主 guolichun 的回复:
读取一个文件的前1000个字节,做异或处理,之后拿异或处理得到的1000个字节替换文件的前1000个字节,并把文件保存。


谁能帮帮我,

异或是不是只能针对字节操作,(在进行简单异或加密的时候),

怎么才能仅仅读取一个文件的前1000个字节,?


之后如何拿1000个字节去替换文件的前1000个字节,并保存呢?!


FileStream,一个字节一个字节往下读,保存在List<Byte>中,然后,只异或前1000个字节,
然后重新创建这个文件,List<Byte>写~

楼主想做简单的加密?
再异或一次就是解密了。 --------------------编程问答-------------------- 异或怎么、写?1000个字节异或1000个字节的的。


是有矩阵循环还是for就可以了》! --------------------编程问答--------------------

class ReadWriteTxt
    {
        public static void Main()
        {
            string filePath = @"C:\FileReadWriteTest\test.txt";
            if (File.Exists(filePath))
            {
                ReadWriteTxtFile(filePath);
            }
        }

        private static void ReadWriteTxtFile(string filePath)
        {
            FileStream fs = null;
            int byteCount = 0;
            List<byte> byteContent = new List<byte>();
            //byte[] byteContent = new byte[] { };
            byte byteTemp;
            try
            {
                fs = new FileStream(filePath, FileMode.Open);
                Console.WriteLine(fs.Length);
                while (byteCount < fs.Length)
                {
                    byteTemp = (byte)fs.ReadByte();
                    if (byteContent.Count <= 1000)
                    {
                        byteContent.Add((byte)((int)byteTemp ^ (int)byteTemp));
                    }
                    else
                    {
                        byteContent.Add(byteTemp);
                    }
                    byteCount++;
                }
                fs.Dispose();
                fs = new FileStream(filePath, FileMode.Create);
                foreach (byte var in byteContent)
                {
                    fs.WriteByte(var);
                }

            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (fs != null)
                    fs.Dispose();
            }
        }
    }
--------------------编程问答-------------------- 中间有个
fs.Dispose();
改成fs.close(),增加点点点点性能~~
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,