#!/usr/bin/tclsh package require http package require Tk set baseUrl "http://0x0.st/" set seed "XG8y" set extensionListPlain [list ".txt" ".log" ".cpp" ".c" ".py" ".ini" ".json" ".yaml" ".tcl"] set extensionListImage [list ".png" ".jpg" ".jpeg"] proc charFiniteArtimetric {char operator} { if {$operator == "+"} { if {$char == "z"} { return [list "A" 1] } if {$char == "Z"} { return [list "a" 1] } } if {$operator == "-"} { if {$char == "a"} { return [list "Z" 1] } if {$char == "A"} { return [list "z" 1] } } set asciiValue [scan $char %c] return [list [format %c [expr $asciiValue $operator 1]] 0] } proc stringFiniteArtimetric {str operator n} { set rReverse "" for {set carry 0; set i [expr [string length $str] - 1]} {$i >= 0} {incr i -1} { set c [string index $str $i] for {set h 0} {$h < [expr 1 + $carry]} {incr h} { set rc [charFiniteArtimetric $c $operator] set c [lindex $rc 0] } append rReverse $c if [lindex $rc 1] { set $carry 1 } else { for {set h [expr $i - 1]} {$h >= 0} {incr h -1} { append rReverse [string index $str $h] } break } } set r [string reverse $rReverse] return $r } proc get0x0page {page} { proc loggedGeturl {url} { puts -nonewline "Getting $url..." flush stdout .controls.url configure -text $url set r [http::geturl $url -timeout 1000] puts "done" return $r } .output.output_text delete 1.0 end foreach extension $::extensionListPlain { set url "$::baseUrl$page$extension" set response [loggedGeturl $url] if {[http::ncode $response] == 200} { puts "Page found." .output.output_text insert end [http::data $response] return 1 } } foreach extension $::extensionListImage { set url "$::baseUrl$page$extension" set response [loggedGeturl $url] if {[http::ncode $response] == 200} { set image_data [http::data $response] set file_name "out$extension" set file_id [open $file_name "wb"] puts $file_id $image_data close $file_id .output.output_image delete all .output.output_image create image 0 0 -anchor nw -image [image create photo -file $file_name] return 1 } } .output.output_text insert end "**Missing page**" return 0 } proc previous {} { set ::seed [stringFiniteArtimetric $::seed - 1] return [get0x0page $::seed] } proc next {} { set ::seed [stringFiniteArtimetric $::seed + 1] return [get0x0page $::seed] } proc backward {} { while {![previous]} {} } proc forward {} { while {![next]} { } } proc resizeFont {i} { set font_size [lindex [split [.output.output_text cget -font] " "] 1] if {($i && $font_size >= 100) || (!$i && $font_size <= 0)} { return } set font_size [expr $font_size + $i] .output.output_text configure -font "TkFixedFont $font_size" } wm title . "0x0.st peeper" frame .output pack .output -expand 1 -fill both text .output.output_text -font "TkFixedFont 8" bind .output.output_text {resizeFont 1} bind .output.output_text {resizeFont -1} pack .output.output_text -fill both -expand 1 -side left canvas .output.output_image pack .output.output_image -fill both -expand 1 -side left scrollbar .output.output_scroll -orient vertical -command ".output yview" pack .output.output_scroll -side right -fill y frame .controls pack .controls -side bottom button .controls.backward -text "<<" -command backward button .controls.previous -text "Previous" -command previous button .controls.next -text "Next" -command next button .controls.forward -text ">>" -command forward label .controls.url pack .controls.backward -side left pack .controls.previous -side left pack .controls.next -side left pack .controls.forward -side left pack .controls.url -side right get0x0page $::seed