Skip to content

Instantly share code, notes, and snippets.

@JoshuaMa64
Created June 20, 2019 17:07
Show Gist options
  • Save JoshuaMa64/be1fb6c9bf2033347e9166cb4265dbb7 to your computer and use it in GitHub Desktop.
Save JoshuaMa64/be1fb6c9bf2033347e9166cb4265dbb7 to your computer and use it in GitHub Desktop.
赤痕:夜之仪式 某个武器描述的解密代码
using System;
using System.Globalization;
using System.Linq;
using System.Text;
/// <summary>
/// 本程序意在对游戏 Bloodstained: Ritual of the Night 中出现的武器 Encrypted Orchid 的
/// 武器描述:
///
/// 6F20636B6E7077206772646C7A207A77
/// 6B6A207075707365756C2078726B7674
///
/// 进行解密。直接将原文转写成ASCII值即可得到密文
///
///      o cknpw grdlz zwkj pupseul xrkvt
///      
/// 密文采用了维吉尼亚密码(https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher)进行加密,
/// 密匙已经在武器名中透露(orchid),依照此法解密后可得原文
///
/// a light saber with immense power
///
/// </summary>
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string pwd = "6F20636B6E7077206772646C7A207A77" +
"6B6A207075707365756C2078726B7674";
string key = "orchid";
byte[] pwdArr = new byte[pwd.Length / 2];
for (int i = 0; i < pwd.Length / 2; i++)
{
string s = new string(new char[2] { pwd[i * 2], pwd[i * 2 + 1] });
pwdArr[i] = byte.Parse(s, NumberStyles.AllowHexSpecifier);
}
string output_1 = Encoding.ASCII.GetString(pwdArr);
string output_2 = output_1.Replace(" ", string.Empty);
string output_3 = string.Empty;
for (var i = 0; i < output_2.Length; i++)
{
char first = Convert.ToChar(key[i % key.Length]);
output_3 += Caesar(first, output_2[i]);
}
int index = 0;
foreach (int i in output_1.Split(' ').Select(i => i.Length))
{
index += i;
output_3 = output_3.Insert(index, " ");
index++;
}
Console.WriteLine(output_3);
Console.ReadLine();
}
static char Caesar(char first, char cypher)
{
char offset = Convert.ToChar(first <= cypher ? cypher - first : 26 - first + cypher);
return Convert.ToChar('a' + offset);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment