Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

rot13 encoding and decoding program with a exe file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBCC rot13 encoding and decoding program with a exe file

    ROT13.EXE
    To those people searching for a program to convert/encode a file to a rot13 format such as that used for firefox configuration files. There is a downloadable file below "rot13.zip" that contains the rot13.exe program to do your conversion. It is very smalll program and it was compiled using a compiler made and sold by Powerbasic that creates compac effiecient fast executable code. It was created from source code contributed to this forum by some forum members. Powerbasic is a very easy to learn compiler for creating dos and windows programs. If you always wanted to create your own programs and really do not know where to start or want something that less hard on the learning curve. Then get yourself a Powerbasic compiler and you can do things you never thought you could. Here is just an example. Like Tom pointed out below, there is not a need for assemble code to produce the great results, functions are built into the Powerbasic compiler for handling text in many different ways, but if you wish to include assemble language into your program along with easy to learn basic language, the Powerbasic compiler will let you do it easily. I love to program with the Powerbasic compiler that creates console type programs, the programs that are not graphical, but there is also a Powerbasic compiler that produces graphic user displays(GUI programs). The code is almost the exact same for both compiliers used, and both compilers produce small fast executable files(an exe file). This forum list so much code examples and friendly member help, you would think your best friend is helping you out. I am just a computer user probably like yourself, except for my english writing are terrible, needing help to produce my own custom made executable programs. Well Powerbasic products have made my dreams come true of getting things my way, the way i want them without a lot of fuss. So discover Powerbasic and join this forum so you can benefit from the experience and free consulting of its members, and we can learn from you as well.
    This section of the Powerbasic forum (Source Code) is for listing of source code only and not for general communicating, but i thought a few people out there might find this information from a search program, like google, off the internet and i just wanted to tell you about a great and easy to use programming product that you will not have to sell your kids to purchase.

    OK, back on to my original posting of this program.
    I really cannot see the need to encode a text file to another text file but that seems to be what has to be done to alter some of the firefox browser settings. This is plumb crazy to have to save a file in such a format. Men really are from Mars.


    i originally had both Borje's and Peter's name given credit during the running of this program but i removed it, thinking they not approve of having their names on this program for some kind of liability reasons.
    But hey, thanks Borje and Peter.
    Here is some of your work at work.


    the main work of source comes from two listing at
    http://www.powerbasic.com/support/fo...ML/001173.html

    added:
    and i never did get the results i was trying to get out of firefox, i just found a addon to do my dirty work of securing the browser that worked better than anything i tried after 24 hours plus of work. the addon i needed was called "public fox", give it a try, it works more than great.
    the first program i compiled to do the rot13 never did work proper and i could not duplicate the problem, i checked the rot13 output to some web pages that could convert the text and they where different, but after i copied the code a second time from http://www.pbcrypto.com/view.php?algorithm=rot13 , it all works now. Then i recopied the code from the powerbasic forum post as listed above and it all worked then. Who knows what happened, i do not, i am sure i must of done a copy and paste wrong and it does not matter now. I do love the capability on the forum of being able to upload a list and exe to the forum and it would of came in handy in previous early years when this forum was put on the internet, but all things where new then on the internet. What a developing experience we all had then and for some still today.

    And thanks Tom for the show of the new rot13 work, the replace command is a real winner and will be a flexible function to simplify all kinds of neat work with strings.

    Code:
    'compiler pbcc50 a Powerbasic compiler
    'this program creates a rot13 encoded file from a text file
    ' or if the file is encoded,  it decodes it
    'it creates a file with the same name but with a added extension of ".rot13"
    'this code was created almost entirely by Borje Hagsten and Peter P Stephensen
    'i just pieced the two together
    ' the source comes from two listing at 
    'http://www.powerbasic.com/support/forums/Forum6/HTML/001173.html
    'i could not find a easy program to do this conversion so here it is
    'my need for it was to create some files needed to alter firefox browser setting.
    
    This listing and program might get powerbasic some hits.
    
    #COMPILE EXE  "ROT13.EXE"
    #DIM ALL
    #REGISTER NONE
    
    
    FUNCTION asmROT13(a$) AS STRING
    IF LEN(a$) = 0 THEN EXIT FUNCTION
    #REGISTER NONE
    
      LOCAL ln AS LONG
      ln = LEN(a$)             ' get string's len into ln
    
      ! cmp ln, 0              ; does the string have a length?
      ! je Exit13Loop          ; exit if zero
    
      ! mov eax, a$            ; eax = pointer to string handle
      ! mov eax, [eax]         ; eax = pointer to string data
    
      Bgn13Loop:
         ! mov edx, [eax]      ; move current char into edx
         ! cmp ln, 0           ; exit when ln = zero
         ! jne Continue13Loop
            ! jmp Exit13Loop   ; jump out on end of string
    
      Continue13Loop:
         ! cmp dl, 65          ; CASE 65 TO 90
         ! jb NoRot            ;    if dl < 65  then get next character
         ! cmp dl, 90
         ! jbe Rot13Upper      ;    if dl <= 90
         ! cmp dl, 97          ; CASE 97 TO 122
         ! jb NoRot            ;    if dl < 97  then next character
         ! cmp dl, 122
         ! jbe Rot13Lower      ;    if dl <= 122
         ! jmp NoRot           ; CASE ELSE - get next character
    
      Rot13Lower:
         ! add dl, 13          ; Rotate 13 steps forward
         ! cmp dl, 122
         ! ja AdjChar          ; if dl became > 122
         ! mov [eax], dl       ; else write changed char back into a$
         ! jmp NoRot
    
      Rot13Upper:
         ! add dl, 13          ; Rotate 13 steps forward
         ! cmp dl, 90
         ! ja AdjChar          ; if dl became > 90
         ! mov [eax], dl       ; else write changed char back into a$
         ! jmp NoRot
    
      AdjChar:
         ! sub dl, 26
         ! mov [eax], dl       ; else write changed char back into a$
         ! jmp NoRot
    
      NoRot:
         ! inc eax
         ! dec ln              ; decrease the ln (length) counter
         ! jmp bgn13Loop
    
      Exit13Loop:
    
    FUNCTION=a$
    END FUNCTION
    
    DECLARE FUNCTION GetFile(BYVAL File AS STRING, Buffer AS STRING) AS LONG
    DECLARE FUNCTION PutFile(BYVAL File AS STRING, Buffer AS STRING) AS LONG
    
    FUNCTION ROT13(File AS STRING,newfile AS STRING)AS LONG
        DIM newbuffer AS STRING
        LOCAL pl AS LONG POINTER
        LOCAL Buffer AS STRING
        LOCAL n AS LONG, i AS LONG
    
        IF GetFile(File, Buffer) = 0 THEN EXIT FUNCTION
        newbuffer=asmROT13(buffer)
    
        PutFile NewFile, newbuffer
    
        FUNCTION = 1
    
    END FUNCTION
    
    '===============================
    
    FUNCTION PBMAIN
       FUNCTION=1
       DIM tempfile AS STRING
       tempfile=TRIM$(COMMAND$)
       REPLACE $DQ WITH "" IN tempfile
       tempfile=TRIM$(tempfile)
       IF LEN(tempfile)=0 THEN
            STDOUT "place a file name on the command tail"
            STDOUT "program encodes a file to and from rot13 format"
            STDOUT "output name will have an extension of .rot13 added to it"
            EXIT FUNCTION
       END IF
       IF ISFILE(tempfile)=0 THEN STDOUT "no file found -- "+tempfile:EXIT FUNCTION
       
       IF rot13(tempfile, tempfile+".rot13") THEN
            STDOUT tempfile+".rot13  created"
            ELSE
            STDOUT "error in reading "+tempfile+" or creating "+tempfile+".rot13"
            FUNCTION=0
       END IF
    
    END FUNCTION
    
    '===============================
    
    FUNCTION GetFile(BYVAL File AS STRING, Buffer AS STRING) AS LONG
    
        LOCAL hFile AS LONG
    
        ERR = 0 : hFile = FREEFILE
    
        OPEN file FOR BINARY AS hFile
        IF ERR THEN EXIT FUNCTION
        GET$ hFile, LOF(hFile), Buffer
        CLOSE hFile
    
        FUNCTION = 1
    
    END FUNCTION
    
    '===============================
    
    FUNCTION PutFile(BYVAL File AS STRING, Buffer AS STRING) AS LONG
    
        LOCAL hFile AS LONG
    
        ERR = 0 : hFile = FREEFILE
    
        OPEN File FOR BINARY AS hFile
        IF ERR THEN EXIT FUNCTION
        PUT$ hFile, Buffer
        CLOSE hFile
    
        FUNCTION = 1
    
    END FUNCTION
    Attached Files
    Last edited by Paul Purvis; 13 Sep 2009, 12:28 AM.
    p purvis

  • #2
    Borje was (is?) a brilliant programmer, but I hope he continued to practice his assembly language. There isn't much call for asm here, though. I've slapped together a somewhat simpler version in pure PowerBASIC.

    Code:
    ' SROT13  Public Domain  Thomas G. Hanlin III
    ' PowerBASIC Console Compiler 5
    
    #COMPILE EXE
    #DIM ALL
    
    
    
    FUNCTION GetFile (BYVAL sFile AS STRING, sBuffer AS STRING) AS LONG
    
        LOCAL nFile AS LONG
    
        nFile = FREEFILE
    
        TRY
            OPEN sFile FOR BINARY AS nFile
            GET$ nFile, LOF(nFile), sBuffer
            FUNCTION = 1
        CATCH
            STDERR "Unable to read file: " + sFile
        FINALLY
            CLOSE nFile
        END TRY
    
    END FUNCTION
    
    
    
    FUNCTION PutFile (BYVAL sFile AS STRING, sBuffer AS STRING) AS LONG
    
        LOCAL nFile AS LONG
    
        nFile = FREEFILE
    
        TRY
            OPEN sFile FOR BINARY AS nFile
            PUT$ nFile, sBuffer
            FUNCTION = 1
        CATCH
            STDERR "Unable to write file: " + sFile
        FINALLY
            CLOSE nFile
        END TRY
    
    END FUNCTION
    
    
    
    FUNCTION PBMAIN () AS LONG
    
        LOCAL sFile AS STRING
        LOCAL sBuffer AS STRING
    
        sFile = TRIM$(COMMAND$)
        REPLACE $DQ WITH "" IN sFile
    
        IF LEN(sFile) = 0 THEN
            STDERR "SROT13 encodes or decodes a file using Rot13. Syntax:"
            STDERR
            STDERR "SROT13 filename"
            STDERR
            STDERR "The results will be in filename.13"
            FUNCTION = 2
            EXIT FUNCTION
        END IF
    
        IF GetFile(sFile, sBuffer) THEN
            REPLACE ANY CHR$(ASC("A") TO ASC("Z"), ASC("a") TO ASC("z")) _
                   WITH CHR$(ASC("N") TO ASC("Z"), ASC("A") TO ASC("M"), _
                             ASC("n") TO ASC("z"), ASC("a") TO ASC("m")) _
                   IN sBuffer
            IF PutFile(sFile + ".13", sBuffer) THEN
                STDOUT "Created: " + sFile + ".13"
                EXIT FUNCTION
            END IF
        END IF
    
        FUNCTION = 1
    
    END FUNCTION
    Last edited by Tom Hanlin; 13 Sep 2009, 11:02 AM.

    Comment


    • #3
      Just a little addition to Tom's code: Wrapped the Rot13 code into a function. Added a Rot5 function for numerical values and a function which combines Ro13 and Rof5.

      Code:
      '--------------------------------------------------------------------------------
      ' Rot13
      ' Rot13 Encryption
      '--------------------------------------------------------------------------------
      Function Rot13( orgstr As String ) As String
         Replace Any Chr$(Asc("A") To Asc("Z"), Asc("a") To Asc("z")) _
                     With Chr$(Asc("N") To Asc("Z"), Asc("A") To Asc("M"), _
                     Asc("n") To Asc("z"), Asc("a") To Asc("m")) _
                     In orgstr
         Function = orgstr
      End Function
      
      
      '--------------------------------------------------------------------------------
      ' Rot5
      ' Rot5 Encryption for number
      '--------------------------------------------------------------------------------
      Function Rot5( orgstr As String ) As String
         Replace Any Chr$(Asc("0") To Asc("9")) _
                     With Chr$(Asc("5") To Asc("9"), Asc("0") To Asc("4")) _
                     In orgstr
         Function = orgstr
      End Function
      
      
      '--------------------------------------------------------------------------------
      ' RotEncrypt
      ' Encrypts a string in Rot13 for alphabetic
      ' and in Rot5 for numeric values
      '--------------------------------------------------------------------------------
      Function RotEncrypt( orgstr As String ) As String
         Replace Any Chr$(Asc("A") To Asc("Z"), Asc("a") To Asc("z")) _
                     With Chr$(Asc("N") To Asc("Z"), Asc("A") To Asc("M"), _
                     Asc("n") To Asc("z"), Asc("a") To Asc("m")) _
                     In orgstr
         Replace Any Chr$(Asc("0") To Asc("9")) _
                     With Chr$(Asc("5") To Asc("9"), Asc("0") To Asc("4")) _
                     In orgstr
         
         Function = orgstr
      End Function
      Last edited by Rolf Brandt; 7 Jan 2010, 12:14 PM.

      Comment

      Working...
      X