S
S
star_trek_voyager2017-03-12 16:43:48
Encryption
star_trek_voyager, 2017-03-12 16:43:48

Implementing CR4 in C#?

solved encryption using the RC4 algorithm, found this post
and took the code from there.
this is how I pass data to the code:
byte[] pass = ASCIIEncoding.Unicode.GetBytes(TBpass.Text);
RC4 encoder = new RC4(pass);
string textCrypt = TBtext.Text;
byte[] ByteCrypt = ASCIIEncoding.Unicode.GetBytes(textCrypt);
byte[] result = encoder.Encode(ByteCrypt, ByteCrypt.Length);
string strout = UTF8Encoding.Unicode.GetString(result, 0, result.Length);
tbtext.text = strout;
text: 1111111111111111111111111111111111111111111111111111111111111111111111111111111
key: 123456
Conclusion: 藰 죻쿝 職郹萴 ⋛ 㤮 쒇 ǯ 남 남 ᥣ 퇙 58 楁 ꑅ ꑅ ṽ 띟 ䷺ 㾼 డ ⱄ ⱄ 垱兲 맯 ᧘ 无 ⣂ 站  ๳ 䣆 ⒗ 鷺 뛲멵  㪀庢 굪 굪 ׽ ଻ 䧕勃 䧕勃㧽倪퉵䀨忀㔮獐蝗돖ꍛⰗᘏႣ䭀䃊槟⟦⌈糔㇅樈㲰얋ഝ瞮㘧
when trying to decode, it gives the following
:

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tom Nolane, 2017-03-12
@tomnolane

look at the lines.... in your code...

byte[] pass = ASCIIEncoding.Unicode.GetBytes(TBpass.Text);
RC4 encoder = new RC4(pass);
string textCrypt = TBtext.Text;
byte[] ByteCrypt = ASCIIEncoding.Unicode.GetBytes(textCrypt);
byte[] result = encoder.Encode(ByteCrypt, ByteCrypt.Length);
string strout = ASCIIEncoding.Unicode.GetString(result, 0, result.Length); // UTF8Encoding поменять на ASCIIEncoding
TBtext.Text = strout;

ps didn't test it... but you have a different encoding for it...
p.s.s. in your link to the site (article) a piece of code:
byte[] key = ASCIIEncoding.ASCII.GetBytes("Key");

RC4 encoder = new RC4(key);
string testString = "Plaintext";
byte[] testBytes = ASCIIEncoding.ASCII.GetBytes(testString);
byte[] result = encoder.Encode(testBytes, testBytes.Length);

RC4 decoder = new RC4(key);
byte[] decryptedBytes = decoder.Decode(result, result.Length);
string decryptedString = ASCIIEncoding.ASCII.GetString(decryptedBytes);

ASCIIEncoding and UTF8Encoding encodings are not mixed anywhere (and they are mixed in your code)

A
Anvar Shakhmaev, 2017-03-12
@RxR

I did not test the code at the link you provided, but successfully implemented this algorithm using the code from the wiki - https://en.wikibooks.org/wiki/%D0%A0%D0%B5%D0%B0%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question