Oh, what’s that? You need me to process a huge file and spew out the data plus its Base64? I’d better write a new .Net proje-OH NO WAIT A MINUTE I DON’T HAVE TO ANY MORE!
ScriptCS is C# from the command line; no project file, no visual studio (.. no intellisense..), but it’s perfect for little hacks like these.
First, go and install Chocoloatey package manager:
c:> @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
Then use chocolatey to install scriptcs:
cinst scriptcs
Then open your text editor of choice (I used SublimeText2 for this one) and write some basic C# plus references, save it as e.g. hasher.csx:
[csharp]
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
var sourceFile = @"C:\Users\rposbo\import.txt";
var destinationFile = @"C:\Users\rposbo\export.txt";
var lines = File.ReadAllLines(sourceFile);
var newOutput = new List<string>();
foreach(var line in lines){
var hash = Convert.ToBase64String(Encoding.Default.GetBytes(line));
newOutput.Add(string.Format("{0},{1}",line,hash));
}
File.WriteAllLines(destinationFile, newOutput.ToArray());
[/csharp]
Then run that from the command line:
c:\Users\rposbo\> scriptcs hasher.csx
And you’ll end up with your output; minimal fuss and effort.
great article, very usefull,
I use this site to encode/decode base 64.
http://www.ebase64encode.org