开发者

fast encryption for a large unicode text file

开发者 https://www.devze.com 2023-02-16 13:46 出处:网络
I have a large unicode text file (35 MB) containing words separated by punctuation marks. I need to somehow hide the content of the file (at least from the majority of people who are not specialised i

I have a large unicode text file (35 MB) containing words separated by punctuation marks. I need to somehow hide the content of the file (at least from the majority of people who are not specialised in cracking).

The best way until now seemed like encryption. I know almost nothing about encryptio开发者_StackOverflow社区n. I tried to use the solution to a similar question "Simple 2 way encryption for C#" but it takes a long time to execute the encryption.

What is the fastest way (algorithm) that works out of the box (i.e. it is contained in the .Net lib)? A short example on how to use it would be nice :) I don't care how strong the encryption is, if you open the encrypted file with a text editor and don't see the words then it's perfect. The important part is speed.


AES is pretty fast still, here's some help implementing it : Using AES encryption in C#

Anything other than industry standard Encryption is asking for problems sooner or later.


What have you tried so far? Are standard encryptions like AES and blowfish too slow?

You can always do something simple like xor-ing the contents against some pass-code repeated to the same length as the file.


As tilleryj said

xor-ing the contents against some pass-code repeated to the same length as the file is simple and fast

but it is les safe then other encription types. I wrote a simple class that helps you encript a string using another string as a password usig the xor method. hope some else can use it.

`using System;
using System.Text;

namespace MyEncriptionNameSpace { class XorStringEncripter { private string __passWord; public XorStringEncripter(string password) { if (password.Length == 0) { throw new Exception("invalide password"); } __passWord = password; } public string encript(string stringToEncript) { return __encript(stringToEncript); }

public string decript(string encripTedString) { return __encript(encripTedString); } public string __encript(string stringToEncript) { var encriptedStringBuilder = new StringBuilder(stringToEncript.Length); int positionInPassword = 0; for (int i = 0; i < stringToEncript.Length; i++) { __corectPositionInPassWord(ref positionInPassword); encriptedStringBuilder.Append((char)((int)stringToEncript[i] ^ (int)__passWord[positionInPassword])); ++positionInPassword; } return encriptedStringBuilder.ToString(); } private void __corectPositionInPassWord(ref int positionInPassword) { if (positionInPassword == __passWord.Length) { positionInPassword = 0; } } }

}`

actualy encript and decript do the same thing , I provided bouth to avoid confusion on using the same function for bouth encription and decrition. This is because if you have a nuber A and you xor it with B and you obtain C then if you xor C and B you get A.
A xor B = C ---> C xor B = A

0

精彩评论

暂无评论...
验证码 换一张
取 消