Created
October 12, 2020 17:53
-
-
Save fionera/9dead791f6238fa86783920acef467eb to your computer and use it in GitHub Desktop.
Decode this stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Security.Cryptography; | |
using System.Text; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
private byte[] bDebug = new byte[16] | |
{ | |
(byte) 37, | |
(byte) 157, | |
(byte) 159, | |
(byte) 101, | |
(byte) 198, | |
(byte) 147, | |
(byte) 67, | |
(byte) 0, | |
(byte) 237, | |
(byte) 74, | |
(byte) 37, | |
(byte) 60, | |
(byte) 81, | |
(byte) 202, | |
(byte) 22, | |
(byte) 112 | |
}; | |
private static char[] cHexCodes = new char[16] | |
{ | |
'0', | |
'1', | |
'2', | |
'3', | |
'4', | |
'5', | |
'6', | |
'7', | |
'8', | |
'9', | |
'A', | |
'B', | |
'C', | |
'D', | |
'E', | |
'F' | |
}; | |
private string sTryingToLogin = "Trying to login..."; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine((new Program()).sAssertAgain(args[0])); | |
} | |
public string sAssertAgain(string sData) => DecryptData(DecryptData(this.sTryingToLogin, Bin2Hex(this.bDebug)), sData); | |
private static byte[] GetIVector(string sPassword) | |
{ | |
byte[] bytes = Encoding.Default.GetBytes(sPassword.PadLeft(8, ' ')); | |
byte[] numArray = new byte[8]; | |
for (int index = 0; index < 8; ++index) | |
numArray[index] = bytes[index]; | |
return numArray; | |
} | |
public static string DecryptData(string sPassword, string sData) | |
{ | |
byte[] bytes = Encoding.Default.GetBytes(sPassword.PadLeft(24, ' ')); | |
byte[] ivector = GetIVector(sPassword); | |
byte[] buffer1 = Hex2Bin(sData); | |
using (TripleDESCryptoServiceProvider cryptoServiceProvider = new TripleDESCryptoServiceProvider()) | |
{ | |
MemoryStream memoryStream = new MemoryStream(); | |
CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, cryptoServiceProvider.CreateDecryptor(bytes, ivector), CryptoStreamMode.Write); | |
cryptoStream.Write(buffer1, 0, buffer1.Length); | |
cryptoStream.FlushFinalBlock(); | |
byte[] buffer2 = memoryStream.GetBuffer(); | |
return Encoding.Default.GetString(buffer2, 0, (int)memoryStream.Length); | |
} | |
} | |
public static byte Hex2Byte(string HexSource) => HexSource.Length == 2 ? (byte)Convert.ToInt32(HexSource, 16) : throw new Exception("Wrong length of HexSource=" + HexSource.Length.ToString()); | |
public static string Hex2Str(string HexSource) | |
{ | |
byte[] bytes = new byte[HexSource.Length / 2]; | |
for (int startIndex = 0; startIndex < HexSource.Length; startIndex += 2) | |
{ | |
Convert.ToInt32(HexSource.Substring(startIndex, 2), 16).ToString(); | |
bytes[startIndex / 2] = Convert.ToByte(HexSource.Substring(startIndex, 2), 16); | |
} | |
return Encoding.Default.GetString(bytes); | |
} | |
public static byte HexChar2Int(char cChar) => cChar >= '0' && cChar <= '9' ? (byte)((uint)cChar - 48U) : (byte)(10U + (uint)(byte)((uint)cChar - 65U)); | |
public static byte[] Hex2Bin(string HexSource) | |
{ | |
byte[] numArray = new byte[HexSource.Length / 2]; | |
for (int index = 0; index < HexSource.Length; index += 2) | |
{ | |
byte num1 = HexChar2Int(HexSource[index]); | |
byte num2 = HexChar2Int(HexSource[index + 1]); | |
numArray[index / 2] = (byte)(((uint)num1 << 4) + (uint)num2); | |
} | |
return numArray; | |
} | |
public static string Bin2Hex(byte[] cString) => Bin2Hex(cString, cString.Length); | |
public static string Bin2Hex(byte[] cString, int iLength) | |
{ | |
byte[] bytes = new byte[iLength * 2]; | |
for (int index = 0; index < iLength; ++index) | |
{ | |
byte num = cString[index]; | |
bytes[index << 1] = (byte)cHexCodes[(int)num / 16]; | |
bytes[(index << 1) + 1] = (byte)cHexCodes[(int)num % 16]; | |
} | |
return Encoding.Default.GetString(bytes); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment