Working out this character conversion

This topic contains 6 replies, has 3 voices, and was last updated by Profile photo of Tore Groneng Tore Groneng 1 year, 4 months ago.

  • Author
    Posts
  • #31467
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi,

    This clever chap has used the below to display his e-mail address.

    I can work some of it out, string length is 33, foreach Character or number...

    then i'm not sure how hes done the rest ? Quite like to do it for my e-mail !

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    
  • #31468
    Profile photo of Tore Groneng
    Tore Groneng
    Participant

    This will generate the number string for you:

    You then have to replace the (0..33) range expression to reflect the length of your email minus one as it is a null-based array.

    Cheers

  • #31469
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Sorry Tore, what will generate the number string ?

  • #31471
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Thank you.
    Could you break it down so i can understand it a bit more please ?

  • #31475
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Here is how it works. It should be easier to read if you copy and paste into the Windows Powershell ISE

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    
    # Let's space it out
    
    [string](0..33 |
             % {
                   [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))
               }
            )-replace " "
    
    # Let's replace the shorthand
    
    [string](0..33 |
             ForEach-Object {
                                [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))
                            }
            )-replace " "
    
    # Now Let's read it
    
    # [string]() cast the result of processing everything in the () as a string. So inside of the () we have.
    
    0..33 |
             ForEach-Object {
                                [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))
                            }
    
    # We start with a range 0 to 33.
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,30, 31, 32, 33 |
             ForEach-Object {
                                [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))
                            }
    
    # That is then piped into a ForEach-Object. The basic result is that the formula in the foreach-object block will run for the for the number
    # of times specified by the range. In this case 34 times. If we start plugging in the value from the range we can calculate the formula
    [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))
    
    # Substituing the first object in the range, 0, for $_, we get the below.
    [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring((0*2),2))
    
    # 0 * 2 is 0, so the result is that we are going to take a substring of the below number starting at position 0 and only continue for 2 characters
    [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(0,2))
    
    # The result of the substring above is 68. We then add 46 to 68
    [char][int](46 + 68)
    
    # The result of that addition is 114
    [char][int](114)
    
    # The result is then cast as an integer and then as a charater. The result of the casting is the character who's ASCII number is 114
    r
    
    # This then repeats for each number in the range
    [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring((1*2),2))
    [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring(2,2))
    [char][int](46 + 65)
    [char][int](111)
    o
    
    [char][int](46 + ("686552495351636652556262185355647068516270555358646562655775 0645570").substring((2*2),2))
    b
    
    # etc.etc.
    
    # After the ForEach-Object loop has finished processing for each value in the range you end up with an array of string objects inside of the ()
    [string]("r", "o", "b", "_", "c", "a", "m", "p", "b", "e", "l", "l", "@", "c", "e", "n", "t", "r", "a", "l", "t", "e", "c", "h", "n", "o", "l", "o", "g", "y", ".", "n", "e", "t")-replace " "
    
    # [string] casts the value inside of the () as a string instead of an array, which bacially joins all of the array elements together into a string
    # with a space between each element of the array
    "r o b _ c a m p b e l l @ c e n t r a l t e c h n o l o g y . n e t"-replace " "
    
    # And finally -replace " " replaces all the space characters with nothing
    "rob_campbell@centraltechnology.net"
    
  • #31481
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Thank you very much Curtis for taking the time to do this. I will paste it in the ISE and go through it.

  • #31498
    Profile photo of Tore Groneng
    Tore Groneng
    Participant

    Curtis – respect!

You must be logged in to reply to this topic.