TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
siabanie banie
NA
68
74.2k
Plaintext + Cipher
Nov 5 2011 10:39 PM
This is a continuing from previous forum that has been removed for no reason why! - I just don't understand that all the thread seems disappear. I think something wrong with the setting anyhow here is the latest one: Vulpes, I think for now we use the C sharpe version with these Keys and cipher text.
The code still in testing so will see what went wrong on here. Thanks.
PS: Could it be that the text is encoded with padding?
using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;
class Program
{
static void Main()
{
Encoding ascii = Encoding.ASCII;
byte[] key = {0x9b, 0x4c, 0x3d, 0x50, 0x3b, 0x00, 0x00, 0x00}; // use null bytes initially
byte[] cipherText2 = {0x2e, 0x4c, 0x56, 0xe7, 0xf9, 0xf9, 0xd0, 0xef,
0xab, 0x3c, 0x4d, 0x2e, 0x2f, 0x21, 0xf5, 0xcd,
0x8e, 0x9e, 0xd0, 0xf8, 0xe7, 0xa8, 0xd0, 0xbc};
byte[] cipherText = null;
byte[] plainText = null;
string s = null;
bool isCandidate = false;
StreamWriter sw = new StreamWriter("candidates.txt");
for(int i = 0; i < 255; i += 2)
{
for(int j = 0; j < 255; j += 2)
{
for(int k = 0; k < 255; k += 2)
{
key[5] = (byte)i;
key[6] = (byte)j;
key[7] = (byte)k;
cipherText = DesDecrypt(cipherText2, key);
plainText = DesDecrypt(cipherText, key);
s = ascii.GetString(plainText);
isCandidate = true;
foreach(char c in s)
{
int ascval = (int)c;
if (ascval == 63 || ascval < 32 || ascval > 126)
{
isCandidate = false;
break;
}
}
if (isCandidate)
{
string result = String.Format("{0} : {1} : {2} - {3}", i, j, k, s); // now includes bytes
Console.WriteLine(result); // now writes candidate to console as well
sw.WriteLine(result);
}
}
}
Console.WriteLine("i = {0} completed", i); // indication of where we're at
}
sw.Close();
}
static byte[] DesEncrypt(byte[] plainText, byte[] key)
{
// Create a new DES key.
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
// Set the KeySize = 64 for 56-bit DES encryption.
// The msb of each byte is a parity bit, so the key length is actually 56 bits.
des.KeySize = 64;
des.Key = key;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
ICryptoTransform ic = des.CreateEncryptor();
byte[] enc = ic.TransformFinalBlock(plainText, 0, 24); // 24 bytes assumed
return enc;
}
static byte[] DesDecrypt(byte[] cipherText, byte[] key)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.KeySize = 64;
des.Key = key;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
ICryptoTransform ic = des.CreateDecryptor();
byte[] dec = ic.TransformFinalBlock(cipherText, 0, 24);
return dec;
}
}
Reply
Answers (
30
)
Crystal Report -how to hide formula field as per the condition
C#: Implementing Image Secret Sharing.