VBScript – Translating Characters that have been Substituted

email me

This is the second part of a substitution program I wrote (this is the decoder portion); the first part was in C# (the encoder). Originally, I wrote both parts in C#, but had people asking me for something that did not require compiling to use in their scripts, so I created this VBScript. The idea is…the encoded string is accepted by the script and then translated into its original form.

This script could be utilized for encoding and decoding if you reverse (or create a function to reverse) the translation sequences (permutations).

Note, you want to make sure you change the sequences, to provide a level of uniqueness for your environment.

 

Option Explicit

Dim strShift, strPassword, WshShell, bufferLength, i, retValue

Set WshShell = WScript.CreateObject("WScript.Shell")


'Verify if reg key exists
KeyExists "SOFTWARE\Wow6432Node\ZWT", "ZWT1"
if retValue = "False" then WScript.Quit(1)

'Return Password
Translate()

'strPassword is translated password
'this will be what is used for elevated apps
msgbox strPassword

WScript.Quit()


'do not edit below this line unless changing permutations
'---------------------------------------------------
sub Translate()

'clip or output file could be used to grab output
CreateObject("WScript.Shell").Run "cmd /c RegRead.exe | clip", 0, True

strShift = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
strShift = trim(strShift)
strShift = replace(strShift,chr(13),"")

Dim buffer()
bufferLength = Len(strShift)
ReDim buffer(bufferLength)
For i = 1 To Len(strShift)
buffer(i) = Mid(strShift,i,1)

Do While True
if buffer(i) = "O" then buffer(i) = "A" : exit do
if buffer(i) = "K" then buffer(i) = "B" : exit do
if buffer(i) = "I" then buffer(i) = "C" : exit do
if buffer(i) = "R" then buffer(i) = "D" : exit do
if buffer(i) = "B" then buffer(i) = "E" : exit do
if buffer(i) = "H" then buffer(i) = "F" : exit do
if buffer(i) = "P" then buffer(i) = "G" : exit do
if buffer(i) = "W" then buffer(i) = "H" : exit do
if buffer(i) = "J" then buffer(i) = "I" : exit do
if buffer(i) = "V" then buffer(i) = "J" : exit do
if buffer(i) = "G" then buffer(i) = "K" : exit do
if buffer(i) = "A" then buffer(i) = "L" : exit do
if buffer(i) = "C" then buffer(i) = "M" : exit do
if buffer(i) = "T" then buffer(i) = "N" : exit do
if buffer(i) = "N" then buffer(i) = "O" : exit do
if buffer(i) = "Q" then buffer(i) = "P" : exit do
if buffer(i) = "U" then buffer(i) = "Q" : exit do
if buffer(i) = "E" then buffer(i) = "R" : exit do
if buffer(i) = "F" then buffer(i) = "S" : exit do
if buffer(i) = "Y" then buffer(i) = "T" : exit do
if buffer(i) = "D" then buffer(i) = "U" : exit do
if buffer(i) = "Z" then buffer(i) = "V" : exit do
if buffer(i) = "S" then buffer(i) = "W" : exit do
if buffer(i) = "L" then buffer(i) = "X" : exit do
if buffer(i) = "M" then buffer(i) = "Y" : exit do
if buffer(i) = "X" then buffer(i) = "Z" : exit do

if buffer(i) = "o" then buffer(i) = "a" : exit do
if buffer(i) = "k" then buffer(i) = "b" : exit do
if buffer(i) = "i" then buffer(i) = "c" : exit do
if buffer(i) = "r" then buffer(i) = "d" : exit do
if buffer(i) = "b" then buffer(i) = "e" : exit do
if buffer(i) = "h" then buffer(i) = "f" : exit do
if buffer(i) = "p" then buffer(i) = "g" : exit do
if buffer(i) = "w" then buffer(i) = "h" : exit do
if buffer(i) = "j" then buffer(i) = "i" : exit do
if buffer(i) = "v" then buffer(i) = "j" : exit do
if buffer(i) = "g" then buffer(i) = "k" : exit do
if buffer(i) = "a" then buffer(i) = "l" : exit do
if buffer(i) = "c" then buffer(i) = "m" : exit do
if buffer(i) = "t" then buffer(i) = "n" : exit do
if buffer(i) = "n" then buffer(i) = "o" : exit do
if buffer(i) = "q" then buffer(i) = "p" : exit do
if buffer(i) = "u" then buffer(i) = "q" : exit do
if buffer(i) = "e" then buffer(i) = "r" : exit do
if buffer(i) = "f" then buffer(i) = "s" : exit do
if buffer(i) = "y" then buffer(i) = "t" : exit do
if buffer(i) = "d" then buffer(i) = "u" : exit do
if buffer(i) = "z" then buffer(i) = "v" : exit do
if buffer(i) = "s" then buffer(i) = "w" : exit do
if buffer(i) = "l" then buffer(i) = "x" : exit do
if buffer(i) = "m" then buffer(i) = "y" : exit do
if buffer(i) = "x" then buffer(i) = "z" : exit do

if buffer(i) = "7" then buffer(i) = "0" : exit do
if buffer(i) = "4" then buffer(i) = "1" : exit do
if buffer(i) = "9" then buffer(i) = "2" : exit do
if buffer(i) = "5" then buffer(i) = "3" : exit do
if buffer(i) = "3" then buffer(i) = "4" : exit do
if buffer(i) = "6" then buffer(i) = "5" : exit do
if buffer(i) = "0" then buffer(i) = "6" : exit do
if buffer(i) = "1" then buffer(i) = "7" : exit do
if buffer(i) = "2" then buffer(i) = "8" : exit do
if buffer(i) = "8" then buffer(i) = "9" : exit do

if ASC(buffer(i)) = ASC("$") then buffer(i) = CHR(ASC("?")) : exit do
if ASC(buffer(i)) = ASC("?") then buffer(i) = CHR(ASC("$")) : exit do

if ASC(buffer(i)) = ASC("~") then buffer(i) = CHR(ASC("@")) : exit do
if ASC(buffer(i)) = ASC("@") then buffer(i) = CHR(ASC("~")) : exit do

if ASC(buffer(i)) = ASC("%") then buffer(i) = CHR(ASC("!")) : exit do
if ASC(buffer(i)) = ASC("!") then buffer(i) = CHR(ASC("%")) : exit do

if ASC(buffer(i)) = ASC("-") then buffer(i) = CHR(ASC("#")) : exit do
if ASC(buffer(i)) = ASC("#") then buffer(i) = CHR(ASC("-")) : exit do

if ASC(buffer(i)) = ASC("*") then buffer(i) = CHR(ASC("(")) : exit do
if ASC(buffer(i)) = ASC("(") then buffer(i) = CHR(ASC("*")) : exit do

if ASC(buffer(i)) = ASC("&") then buffer(i) = CHR(ASC("'")) : exit do
if ASC(buffer(i)) = ASC("'") then buffer(i) = CHR(ASC("&")) : exit do

if ASC(buffer(i)) = ASC("_") then buffer(i) = CHR(ASC(")")) : exit do
if ASC(buffer(i)) = ASC(")") then buffer(i) = CHR(ASC("_")) : exit do

if ASC(buffer(i)) = ASC("^") then buffer(i) = CHR(ASC("+")) : exit do
if ASC(buffer(i)) = ASC("+") then buffer(i) = CHR(ASC("^")) : exit do

if ASC(buffer(i)) = ASC("`") then buffer(i) = CHR(ASC(".")) : exit do
if ASC(buffer(i)) = ASC(".") then buffer(i) = CHR(ASC("`")) : exit do

if ASC(buffer(i)) = ASC(",") then buffer(i) = CHR(ASC("=")) : exit do
if ASC(buffer(i)) = ASC("=") then buffer(i) = CHR(ASC(",")) : exit do

if ASC(buffer(i)) = ASC("\") then buffer(i) = CHR(ASC("/")) : exit do
if ASC(buffer(i)) = ASC("/") then buffer(i) = CHR(ASC("\")) : exit do

if ASC(buffer(i)) = ASC(">") then buffer(i) = CHR(ASC("<")) : exit do
if ASC(buffer(i)) = ASC("{") then buffer(i) = CHR(ASC("}")) : exit do

if ASC(buffer(i)) = ASC("}") then buffer(i) = CHR(ASC("{")) : exit do
if ASC(buffer(i)) = ASC("<") then buffer(i) = CHR(ASC(">")) : exit do

if ASC(buffer(i)) = ASC("]") then buffer(i) = CHR(ASC("[")) : exit do
if ASC(buffer(i)) = ASC("[") then buffer(i) = CHR(ASC("]")) : exit do

if ASC(buffer(i)) = ASC(";") then buffer(i) = CHR(ASC(":")) : exit do
if ASC(buffer(i)) = ASC("|") then buffer(i) = CHR(ASC("|")) : exit do

if ASC(buffer(i)) = ASC(":") then buffer(i) = CHR(ASC("""")) : exit do
if ASC(buffer(i)) = ASC("""") then buffer(i) = CHR(ASC(":")) : exit do
exit do
loop
Next

strPassword = ""

For i = 0 to bufferLength
strPassword = strPassword & buffer(i)
Next

CreateObject("WScript.Shell").Run "cmd /c echo. | clip", 0, True

end sub


sub KeyExists(RegPath, RegKey)
	Const HKEY_LOCAL_MACHINE = &H80000002
	Dim strComputer, objRegistry, RegValue, objWshShell	

	Set objWshShell = CreateObject("WScript.shell")
	
	strComputer = "."
	Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

	objRegistry.GetStringValue HKEY_LOCAL_MACHINE,RegPath,RegKey,RegValue
	
	If Not IsNull(RegValue) Then
	    retValue = True
	Else
	    retValue = False
	End If	
end sub