├── .dockerignore ├── .github └── workflows │ └── dotnetcore.yml ├── .gitignore ├── Controllers ├── DecodeController.cs └── EncodeController.cs ├── Dockerfile ├── Lib ├── AESTool.cs └── EncodeTool.cs ├── Models ├── GlobalConfig.cs ├── Params.cs └── Results.cs ├── Program.cs ├── Properties └── launchSettings.json ├── README.md ├── Startup.cs ├── TimedLogger.cs ├── appsettings.json ├── marysue-encoder.csproj ├── marysue-encoder.sln └── wwwroot ├── css ├── semantic.min.css └── themes │ └── default │ └── assets │ └── fonts │ ├── icons.eot │ ├── icons.svg │ ├── icons.ttf │ ├── icons.woff │ └── icons.woff2 ├── index.html └── js └── semantic.min.js /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /.github/workflows/dotnetcore.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | 17 | - name: Setup .NET 18 | uses: actions/setup-dotnet@v1 19 | with: 20 | dotnet-version: 6.0.x 21 | 22 | - name: Restore dependencies 23 | run: dotnet restore 24 | 25 | - name: Build 26 | run: dotnet build -c Release --no-restore 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Visual Studio Code 28 | .vscode/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | *.VC.db 86 | *.VC.VC.opendb 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # DocProject is a documentation generator add-in 130 | DocProject/buildhelp/ 131 | DocProject/Help/*.HxT 132 | DocProject/Help/*.HxC 133 | DocProject/Help/*.hhc 134 | DocProject/Help/*.hhk 135 | DocProject/Help/*.hhp 136 | DocProject/Help/Html2 137 | DocProject/Help/html 138 | 139 | # Click-Once directory 140 | publish/ 141 | 142 | # Publish Web Output 143 | *.[Pp]ublish.xml 144 | *.azurePubxml 145 | # TODO: Comment the next line if you want to checkin your web deploy settings 146 | # but database connection strings (with potential passwords) will be unencrypted 147 | *.pubxml 148 | *.publishproj 149 | 150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 151 | # checkin your Azure Web App publish settings, but sensitive information contained 152 | # in these scripts will be unencrypted 153 | PublishScripts/ 154 | 155 | # NuGet Packages 156 | *.nupkg 157 | # The packages folder can be ignored because of Package Restore 158 | **/packages/* 159 | # except build/, which is used as an MSBuild target. 160 | !**/packages/build/ 161 | # Uncomment if necessary however generally it will be regenerated when needed 162 | #!**/packages/repositories.config 163 | # NuGet v3's project.json files produces more ignoreable files 164 | *.nuget.props 165 | *.nuget.targets 166 | 167 | # Microsoft Azure Build Output 168 | csx/ 169 | *.build.csdef 170 | 171 | # Microsoft Azure Emulator 172 | ecf/ 173 | rcf/ 174 | 175 | # Windows Store app package directories and files 176 | AppPackages/ 177 | BundleArtifacts/ 178 | Package.StoreAssociation.xml 179 | _pkginfo.txt 180 | 181 | # Visual Studio cache files 182 | # files ending in .cache can be ignored 183 | *.[Cc]ache 184 | # but keep track of directories ending in .cache 185 | !*.[Cc]ache/ 186 | 187 | # Others 188 | ClientBin/ 189 | ~$* 190 | *~ 191 | *.dbmdl 192 | *.dbproj.schemaview 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | -------------------------------------------------------------------------------- /Controllers/DecodeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.Logging; 7 | using MareSueEncoder.Models; 8 | using MareSueEncoder.Lib; 9 | using System.Text; 10 | 11 | namespace MareSueEncoder.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | public class DecodeController : Controller 15 | { 16 | private ILogger _logger; 17 | private const int _decodeMaxLength = 100000; 18 | 19 | public DecodeController(ILogger logger) 20 | { 21 | _logger = logger; 22 | } 23 | 24 | [HttpPost()] 25 | public IActionResult Post([FromBody]DecodeParam param) 26 | { 27 | if (param == null || string.IsNullOrWhiteSpace(param.Code)) 28 | { 29 | _logger.LogError("No param in decoding."); 30 | return BadRequest("no param"); 31 | } 32 | 33 | var code = param.Code.Trim(); 34 | if (code.Length > _decodeMaxLength) 35 | { 36 | _logger.LogError("Decoding param too long: {0}", code.Length); 37 | return BadRequest("param too long"); 38 | } 39 | 40 | var remoteIP = Request.HttpContext.Connection.RemoteIpAddress.ToString(); 41 | try 42 | { 43 | var sourceAes = EncodeTool.StringToByteArray(code); 44 | var source = AESTool.Decrypt(sourceAes); 45 | var sourceStr = Encoding.UTF8.GetString(source); 46 | 47 | _logger.LogInformation($"(IP:{remoteIP})Decoding successfully.\nCode: {code} \nSource: {sourceStr}"); 48 | return new JsonResult(new DecodeResult() { Source = sourceStr }); 49 | } 50 | catch (Exception ex) 51 | { 52 | _logger.LogError($"(IP:{remoteIP})Decoding error for string:\n {code} \nError: {ex.Message}"); 53 | return BadRequest("decode error"); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Controllers/EncodeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using MareSueEncoder.Models; 7 | using System.Text; 8 | using MareSueEncoder.Lib; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace MareSueEncoder.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | public class EncodeController : Controller 15 | { 16 | private ILogger _logger; 17 | private const int _encodeMaxLength = 20000; 18 | 19 | public EncodeController(ILogger logger) 20 | { 21 | _logger = logger; 22 | } 23 | 24 | [HttpPost()] 25 | public IActionResult Post([FromBody]EncodeParam param) 26 | { 27 | _logger.LogDebug("Start Encoding."); 28 | if (param == null || string.IsNullOrWhiteSpace(param.Source)) 29 | { 30 | _logger.LogError("No param in encoding."); 31 | return BadRequest("no param"); 32 | } 33 | 34 | var source = param.Source.Trim(); 35 | if (source.Length> _encodeMaxLength) 36 | { 37 | _logger.LogError($"Encoding param too long: {source.Length}"); 38 | return BadRequest("param too long"); 39 | } 40 | 41 | var remoteIP = Request.HttpContext.Connection.RemoteIpAddress.ToString(); 42 | try 43 | { 44 | var sourceAes = AESTool.Encrypt(Encoding.UTF8.GetBytes(source)); 45 | var code = EncodeTool.ByteArrayToString(sourceAes); 46 | 47 | //var testaes = EncodeTool.StringToByteArray(code); 48 | //if (testaes.Length != sourceAes.Length) 49 | //{ 50 | // for (var i = 0; i < testaes.Length; i++) 51 | // { 52 | // if (testaes[i] != sourceAes[i]) 53 | // { 54 | // _logger.LogError($"Encoding error in {i} of {sourceAes.Length}"); 55 | // break; 56 | // } 57 | // } 58 | //} 59 | 60 | _logger.LogInformation($"(IP:{remoteIP})Encoding successfully.\nSource: {source} \nCode: {code}"); 61 | return new JsonResult(new EncodeResult() { Code = code }); 62 | } 63 | catch( Exception ex) 64 | { 65 | _logger.LogError($"(IP:{remoteIP})Encoding error for string: \n{source} \nError:{ex.Message}"); 66 | return BadRequest("encode error"); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base 4 | WORKDIR /app 5 | EXPOSE 80 6 | 7 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build 8 | WORKDIR /src 9 | COPY ["marysue-encoder.csproj", ""] 10 | RUN dotnet restore "./marysue-encoder.csproj" 11 | COPY . . 12 | WORKDIR "/src/." 13 | RUN dotnet build "marysue-encoder.csproj" -c Release -o /app/build 14 | 15 | FROM build AS publish 16 | RUN dotnet publish "marysue-encoder.csproj" -c Release -o /app/publish 17 | 18 | FROM base AS final 19 | WORKDIR /app 20 | COPY --from=publish /app/publish . 21 | ENTRYPOINT ["dotnet", "marysue-encoder.dll"] -------------------------------------------------------------------------------- /Lib/AESTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MareSueEncoder.Lib 9 | { 10 | /// 11 | /// AES加密工具 12 | /// 13 | public class AESTool 14 | { 15 | /// 16 | /// 加密 17 | /// 18 | /// 原文 19 | /// Key+密文 20 | public static byte[] Encrypt(byte[] Source) 21 | { 22 | var aes = Aes.Create(); 23 | aes.Mode = CipherMode.ECB; 24 | aes.GenerateKey(); 25 | aes.KeySize = 128; 26 | var encryptor = aes.CreateEncryptor(); 27 | var output = encryptor.TransformFinalBlock(Source, 0, Source.Length); 28 | return aes.Key.Concat(output).ToArray(); 29 | } 30 | 31 | /// 32 | /// 解密 33 | /// 34 | /// Key+密文 35 | /// 原文 36 | public static byte[] Decrypt(byte[] Code) 37 | { 38 | var aes = Aes.Create(); 39 | aes.Mode = CipherMode.ECB; 40 | aes.KeySize = 128; 41 | var keyStringLength = aes.KeySize / 8; 42 | if (Code.Length <= keyStringLength) 43 | throw new ArgumentNullException("code too short"); 44 | 45 | aes.Key = Code.Take(keyStringLength).ToArray(); 46 | var decryptor = aes.CreateDecryptor(); 47 | 48 | var realCode = Code.Skip(keyStringLength).ToArray(); 49 | var output = decryptor.TransformFinalBlock(realCode, 0, realCode.Length); 50 | return output; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Lib/EncodeTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using MareSueEncoder.Models; 6 | using Microsoft.Extensions.Logging; 7 | using System.Text; 8 | 9 | namespace MareSueEncoder.Lib 10 | { 11 | public class EncodeTool 12 | { 13 | #region 加密 14 | /// 15 | /// 把字符数组切成1~8随机长度的小数组、转换成ulong数字、生成密文再拼接为长字符串 16 | /// 17 | /// 18 | /// 19 | public static string ByteArrayToString(byte[] source) 20 | { 21 | var cursor = 0; 22 | var length = 0; 23 | var rand = new Random(); 24 | var result = new List(); 25 | 26 | while (cursor < source.Length) 27 | { 28 | length = rand.Next(1, 8); 29 | if (cursor + length > source.Length) length = source.Length - cursor; 30 | 31 | if (source[cursor + length - 1] == 0)//如果小数组最后一位是0,会造成生成数字时无法判断此处为0还是空值,需要重新随机选一次 32 | continue; 33 | 34 | var bytepiece = new byte[8]; 35 | Array.Copy(source, cursor, bytepiece, 0, length); 36 | var number = BitConverter.ToUInt64(bytepiece, 0); 37 | result.Add(UlongToString(number, GlobalConfig.Material)); 38 | cursor += length; 39 | } 40 | 41 | return string.Join(GlobalConfig.Spliter, result.ToArray()); 42 | } 43 | 44 | /// 45 | ///把数字转为最长8个字符 46 | /// 47 | /// 48 | /// 49 | /// 50 | private static string UlongToString(ulong number, string Characters) 51 | { 52 | var result = new List(); 53 | var t = number; 54 | var length = (uint)Characters.Length; 55 | 56 | ulong checkNumber = 0; 57 | 58 | while (t > 0) 59 | { 60 | var q = t % length; 61 | result.Add(Characters[Convert.ToInt32(q)]); 62 | checkNumber = checkNumber * length + q; 63 | t = t / length; 64 | } 65 | return string.Join("", result.ToArray()); 66 | } 67 | #endregion 68 | 69 | #region 解密 70 | /// 71 | /// 把密文字符串拆分成小段,转换成ulong数字再转换成原文字符数组 72 | /// 73 | /// 74 | /// 75 | public static byte[] StringToByteArray(string code) 76 | { 77 | var subCodes = code.Split(new string[] { GlobalConfig.Spliter }, StringSplitOptions.RemoveEmptyEntries); 78 | var source = new List(); 79 | foreach (var subCode in subCodes) 80 | { 81 | var number = StringToUlong(subCode, GlobalConfig.Material); 82 | var sourceBytes = BitConverter.GetBytes(number); 83 | 84 | //去掉数组末尾的0 85 | int trimLength = sourceBytes.Length - 1; 86 | while (sourceBytes[trimLength] == 0) trimLength--; 87 | trimLength++; 88 | var sourceTrim = new byte[trimLength]; 89 | Array.Copy(sourceBytes, sourceTrim, trimLength); 90 | 91 | source.AddRange(sourceTrim); 92 | } 93 | 94 | return source.ToArray(); 95 | } 96 | 97 | /// 98 | /// 把小段密文字符串转换成数字 99 | /// 100 | /// 101 | /// 102 | /// 103 | private static ulong StringToUlong(string text, string Characters) 104 | { 105 | ulong number = 0; 106 | var length = (uint)Characters.Length; 107 | for (var i = text.Length - 1; i >= 0; i--) 108 | { 109 | var q = Characters.IndexOf(text[i]); 110 | if (q == -1) throw new ArgumentOutOfRangeException("illegal characters"); 111 | number = number * length + (uint)q; 112 | } 113 | 114 | return number; 115 | } 116 | #endregion 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Models/GlobalConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace MareSueEncoder.Models 7 | { 8 | public class GlobalConfig 9 | { 10 | public static string Material; 11 | public static string Spliter; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Models/Params.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace MareSueEncoder.Models 7 | { 8 | public class EncodeParam 9 | { 10 | public string Source { get; set; } 11 | } 12 | 13 | public class DecodeParam 14 | { 15 | public string Code { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Models/Results.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace MareSueEncoder.Models 7 | { 8 | public class EncodeResult 9 | { 10 | public string Code { get; set; } 11 | } 12 | 13 | public class DecodeResult 14 | { 15 | public string Source { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace marysue_encoder 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:9022/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "MareSueEncoder": { 12 | "commandName": "Project", 13 | "launchBrowser": true, 14 | "launchUrl": "http://localhost:5081/index.html", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development", 17 | "ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true" 18 | }, 19 | "applicationUrl": "http://localhost:5081/" 20 | }, 21 | "Docker": { 22 | "commandName": "Docker", 23 | "launchBrowser": true, 24 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/index.html", 25 | "publishAllPorts": true 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MarySue Encoder 2 | 3 | ![](https://github.com/atonasting/marysue-encoder/workflows/Build/badge.svg) 4 | 5 | 把任意文字和玛丽苏体的姓名进行加密转换。 6 | 7 | 例: 8 | 9 | 原文: 10 | > 苟利国家生死以 11 | > 岂因祸福避趋之 12 | > ————林则徐 13 | 14 | 转换后: 15 | > 心绯花利蓝妙燢莉·璃之蓝夏阳雅璃·紫曦·米雪银苏吉铃璃·曼燢颜·凡魑陌蒂安·奥语怡馨落糜灵莉·艳姆优凌黛爱·迷晗澪晶安·莎馨·渺·琉伤妮雪璃·雅璃·澪邪璃·情冰·洁瑟芝璃·萝裳雨恩俏黛伤雪·岚烟御文陌安离洁·然·多亚恩陌凡·羽瑷萨璃·凝斯怡璃·陌冰舞茜璃·樱海璃·多曼优安·悠 16 | 17 | 注:每次生成的密文是随机的,但都能解出相同的原文。 18 | 19 | ## Demo 20 | 21 | https://sulian-blog.com/marysue/ 22 | 23 | ## Run 24 | 25 | Written in C#, running on dotnet 6 platform. 26 | 27 | 1. Visit https://dotnet.microsoft.com/en-us/download to install .net runtime 28 | 1. git clone code 29 | 1. cd marysue-encoder 30 | 1. dotnet restore 31 | 1. dotnet run 32 | 1. Visit http://localhost:5001 33 | 34 | ## Develop 35 | 36 | 基本算法 37 | 38 | 1. 首先准备一串字符作为文本素材,并指定某个字符作为分隔符; 39 | 1. 使用随机Key将原文进行AES加密,将密钥附在密文前; 40 | 1. 将加密后的文本随机切分成长度1~8的byte数组,将数组转换成ulong数字; 41 | 1. 设文本素材数量为n,则将ulong数字转换成n进制数,以文本素材作为此数的具体数字; 42 | 1. 使用分隔符将切分后的字符串连接起来,即得密文; 43 | 1. 解密时反向计算即可。 44 | 45 | 给开发者的参考: 46 | 47 | - 修改appsettings.json中的素材与分隔符,可以制作自己版本的密钥生成器; 48 | - 可以附加前后缀文本作为格式与加密版本判断。 49 | 50 | ## Improvment 51 | 52 | - 生成的密文片段中,少数几个文字在末位出现得太过频繁了,应通过算法修正频率; 53 | - 当不使用分隔符时,将随机切分改为固定切分,可以变成无分隔符版密文。 54 | -------------------------------------------------------------------------------- /Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | using MareSueEncoder.Models; 12 | using Microsoft.Extensions.Hosting; 13 | using Microsoft.AspNetCore.Http; 14 | using Microsoft.AspNetCore.HttpOverrides; 15 | 16 | namespace marysue_encoder 17 | { 18 | public class Startup 19 | { 20 | public Startup(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | GlobalConfig.Material = Configuration["Material"]; 24 | GlobalConfig.Spliter = Configuration["Spliter"]; 25 | } 26 | 27 | public IConfiguration Configuration { get; } 28 | 29 | // This method gets called by the runtime. Use this method to add services to the container. 30 | public void ConfigureServices(IServiceCollection services) 31 | { 32 | services.AddControllers(); 33 | services.Configure(options => 34 | { 35 | options.ForwardedHeaders = 36 | ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; 37 | }); 38 | services.AddLogging(options => 39 | { 40 | // Provided by Microsoft.Extensions.Logging.Console 41 | options.AddSimpleConsole(options => 42 | options.TimestampFormat = "[yyyy-MM-dd HH:mm:ss]" 43 | ); 44 | }); 45 | } 46 | 47 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 48 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 49 | { 50 | if (env.IsDevelopment()) 51 | { 52 | app.UseDeveloperExceptionPage(); 53 | } 54 | app.UseForwardedHeaders(); 55 | app.UseStaticFiles(); 56 | app.UseRouting(); 57 | app.UseEndpoints(endpoints => 58 | { 59 | endpoints.MapControllers(); 60 | }); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /TimedLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Logging; 6 | 7 | namespace marysue_encoder 8 | { 9 | public class TimedLogger : ILogger 10 | { 11 | private readonly ILogger _logger; 12 | 13 | public TimedLogger(ILogger logger) => _logger = logger; 14 | 15 | public TimedLogger(ILoggerFactory loggerFactory) : this(new Logger(loggerFactory)) { } 16 | 17 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => 18 | _logger.Log(logLevel, eventId, state, exception, (s, ex) => $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}]: {formatter(s, ex)}"); 19 | 20 | public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel); 21 | 22 | public IDisposable BeginScope(TState state) => _logger.BeginScope(state); 23 | } 24 | } -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Material": "薰璃安莹洁莉樱殇雪羽晗灵血娜丽魑魅塔利亚伤梦儿海蔷玫瑰泪邪凡多姆威恩夏影琉舞雅蕾玥瑷曦月瑟薇蓝岚紫蝶馨琦洛凤颜鸢希玖兮雨烟叶兰凝冰伊如落心语凌爱陌悠千艳优花晶墨阳云筱残莲沫渺琴依然丝可茉黎幽幻银韵倾乐慕文思蕊清碎音芊黛怡莎苏香城萌美迷离白嫩风霜萝妖百合珠喃之倩情恋弥绯芸茜魂澪琪欣呗缈娅吉拉斯基柔惠朵茹妙铃裳纱颖蕴燢浅萦璎糜凪莳娥寂翼巧哀俏涅盘辰芝艾柒曼妲眉御寇妮米菲奥格萨温蒂", 3 | "Spliter": "·", 4 | "Logging": { 5 | "IncludeScopes": false, 6 | "LogLevel": { 7 | "Default": "Debug", 8 | "System": "Information", 9 | "Microsoft": "Warning" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /marysue-encoder.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | 6 | Linux 7 | . 8 | marysue 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /marysue-encoder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2002 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "marysue-encoder", "marysue-encoder.csproj", "{5A6F87C6-8B62-452A-B30A-2F310B87F255}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5A6F87C6-8B62-452A-B30A-2F310B87F255}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {5A6F87C6-8B62-452A-B30A-2F310B87F255}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {5A6F87C6-8B62-452A-B30A-2F310B87F255}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {5A6F87C6-8B62-452A-B30A-2F310B87F255}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C50B0224-64CF-404E-8626-55891BF92EE6} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /wwwroot/css/themes/default/assets/fonts/icons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atonasting/marysue-encoder/404c380e1199da9810e6693c3121ca92bea449f1/wwwroot/css/themes/default/assets/fonts/icons.eot -------------------------------------------------------------------------------- /wwwroot/css/themes/default/assets/fonts/icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atonasting/marysue-encoder/404c380e1199da9810e6693c3121ca92bea449f1/wwwroot/css/themes/default/assets/fonts/icons.ttf -------------------------------------------------------------------------------- /wwwroot/css/themes/default/assets/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atonasting/marysue-encoder/404c380e1199da9810e6693c3121ca92bea449f1/wwwroot/css/themes/default/assets/fonts/icons.woff -------------------------------------------------------------------------------- /wwwroot/css/themes/default/assets/fonts/icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atonasting/marysue-encoder/404c380e1199da9810e6693c3121ca92bea449f1/wwwroot/css/themes/default/assets/fonts/icons.woff2 -------------------------------------------------------------------------------- /wwwroot/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 玛丽苏文本加密器 Mary Sue Text Encoder 6 | 7 | 8 | 9 | 96 | 97 | 114 | 115 | 116 |
117 |
118 |
王氏集团破产中...
119 |
120 |
121 |
122 | 123 | 124 |
125 | 129 | 133 |

134 |
135 | 136 | 137 |
138 |
139 |
140 | 141 | --------------------------------------------------------------------------------