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.

-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

# 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

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

# Convert from System.Int32 to Hex
# Use the .NET Framework formatting methods (see )
# 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
# "e" is 65 in Hex

# So now, we can either do

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

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

"" | %{ -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

\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.

(?<=   )     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.

Here is mine 🙂 :

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

One thought on “Awesome way to share email addresses

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.