hexScope

Page log:

- 2022/06/22 ~ Draft - Code comments may not make true coherent sense. WIP


hexscope is a small utility which where it allows you to inspect indiviual characters of an hexidemical string. This code allows you to inspect each character in a hex string.

All characters are appended to a variable when each time a seperator is found. The seperator is skipped from the addition and the next selection of characters after are then appended to a new variable. In this example we use a switch to differentiate the seperator value, 7c in base16 or as | in base32.

The output is using a base16 string of a1 b7 c3 7c 24 as an example.

Output

>? 0 1 :: a1
>? 2 3 :: b7
>? 4 5 :: c3
seperator found at range: 6 7
>? 6 7 :: 7c
>? 8 9 :: 24

%  puts $variable1
a1b7c3
%  puts $variable2
24

Code with comments

# The length of the string, used for the loop
# The loop will shuffle through our hexstring
# and then check each character of the string
# Using incremented variables values and 
# by examining the character to ensure they match 
# do something

# for loop starts at "0" and $z is incremented
# we are then comparing if variable z is less than the string length
# of our hex string;. Then we increment the variable value x and y variable by one 
# we repeat this 

# within the loop, we debug print the x and y which represent our index of char
# as hex has double digits -- "7" = 37 "3 7"
#                                                                   hex  x y
# increment x, increment x
# increment y, increment y

## The hexstring of the raw input. 
## this is an example of a hexstring 
## within the hexstring variable

set debug 1 ;# debug enabler
set hexString "a1b7c37c24" ;# should be set to the raw input to the hexstring
set cycle 0     ;# internal counter
set x_pos 0                                ;# set the first hex character within the hex string (0)
set y_pos 1                                ;# set the second hex character within the hex string (1)
                                            # as one ascii character uses two hex characters
        switch $debug { 1 { puts ">? x y :: hex" } } ;#debug switch of the x,y and hex that represents those ranges

set string_length [string length $hexString]  ;# get the length of the string example: "abc" = 3  

for {set z 0} {$z < $string_length} {incr z} {  
;# for less than string length, incr $z as $z = cursor point of the length 
                                                
set string_range  [string range "$hexString" $x_pos $y_pos] 
# switch below switches between the string_range 
# the string range is the cursor between the two marks.
# and if the string range output is equal to the value "7c" we then preform a counter increment
# then switch between this cycle 
# 7c is the seperator given to the switch to operate on
# because the string length is longer than the actual inspecting of characters
# we want to break the loop once when the next character is empty
# otherwise this will continue until the forloop reaches the end of the string length.

switch $string_range { 
7c { incr cycle ; switch $debug { 1 { puts "seperator found at range: $x_pos $y_pos" } } }
"" { break }
default { 
                 switch $cycle { 
                 0 { append variable1 $string_range }
                 1 { append variable2 $string_range }
                 }}
} ;#end switch
switch $debug { 1 { puts ">? $x_pos $y_pos :: [string range "$hexString" $x_pos $y_pos]" } }        
                                                ;#show debug for the x y and hexString 
incr x_pos ; incr x_pos ;# incr x_pos twice
incr y_pos ; incr y_pos ;# incr y_pos twice

} ;#end for

Code without comments

set hexString "a1b7c37c24" 
set cycle 0     
set x_pos 0                                
set y_pos 1                                
                                           
set string_length [string length $hexString] 
for {set z 0} {$z < $string_length} {incr z} {         
set string_range  [string range $hexString $x_pos $y_pos] 

switch $string_range { 
7c { incr cycle }
"" { break }
default { 
                 switch $cycle { 
                 0 { append variable1 $string_range }
                 1 { append variable2 $string_range }
                 }}
}
incr x_pos ; incr x_pos
incr y_pos ; incr y_pos
}

puts $variable1
puts $variable2