Awesome way to share email addresses

The guest Karl Mitschke on the scripting guy’s blog plublished a nice way to share his email address.

http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/12/use-a-powershell-script-to-start-non-running-automatic-services.aspx

-join ("6B61726C6D69747363686B65406D742E6E6574" -split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

Let’s see how to explain this syntax construction and if it can be reverse engineered:

# Split the string 2 by 2 characters thanks to a regular expression
"6B61726C6D69747363686B65406D742E6E6574" -split"(?<=\G.{2})"

# 19 is the 'Max substring' option of the split command, which is also half of the full string's length.
# Using the trick will allow to avoid having a carriage return at the end of the split command that will be passed through the pipeline and generate an error

# Do a foreach loop to convert each couple of characters to hexadecimal, then to decimal and finally back to a character
[char][int]"0x$_"

# Use the -join operator to get the result (all converted characters into a single line).

# Now let's do some reverse engineering and see how to generate the hex chain from a string

# Convert from System.String to System.Char
[char]"e"

# Convert from System.Char to System.Int32 (as there's no direct conversion from string to numeric number)
[int][char]"e" -eq 101 
# http://www.asciitable.com/ "e" is 101 in Dec

# Convert from System.Int32 to Hex
# Use the .NET Framework formatting methods (see http://technet.microsoft.com/en-us/library/ee692795.aspx )
# Hexadecimal: The value is displayed as a hexadecimal number. The precision specifier indicates the number of characters to be displayed, with leading zeros added to the beginning as needed.
"{0:X0}" -f ([int][char]"e") -eq 65
# http://www.asciitable.com/ "e" is 65 in Hex

# So now, we can either do

-join ("a.b@c.com" -split "(?<=\G.{1})" | %{if ($_ -ne ""){"{0:X0}" -f ([int][char]"$_")}})

-join ("a.b@c.com" -split "(?<=\G.{1})",("a.b@c.com".length)| %{"{0:X0}" -f ([int][char]"$_")})

"a.b@c.com" | %{ -join ($_ -split "(?<=\G.{1})",($_.length)| %{"{0:X0}" -f ([int][char]"$_")}) }

Here are some explanation of the awsome regular expression used to split a string into 1 or 2 characters

http://msdn.microsoft.com/en-us/library/h5181w5w%28v=VS.71%29.aspx

\G     Specifies that the match must occur at the point where the previous match ended. When used with Match.NextMatch(), this ensures that matches are all contiguous.

http://msdn.microsoft.com/en-us/library/bs2twtah%28v=VS.71%29.aspx

(?<=   )     Zero-width positive lookbehind assertion. Continues match only if the subexpression matches at this position on the left. For example, (?<=19)99 matches instances of 99 that follow 19. This construct does not backtrack.
</blockquote>

Here is mine 🙂 :

-join ("656D696E2E6174616340676D61696C2E636F6D"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
Advertisements

One thought on “Awesome way to share email addresses

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s