locked
How do i use SB to create a program that usses an offset to ecrpyt a message that has been inputted by the user? RRS feed

Answers

  • Hi fanter123

    To do this you can use the operations of Text object.

    GetSubText, GetCharacterCode and GetCharacter. Add then subtract an offset to encrypt and decipher the characters of the plain text and encryption.

    Textboxes would be handy since you can copy/paste in them.

    Using a simple literal offset like this would make the encryption unreadable but very easy to crack! More sophisticated algorithms are used for sensitive data. A simple offset might suitable for not so sensitive data.

    There's a SB extension that encrypts plain text.

    Text.GetCharacterCode("a") + 100 = Encrypted "a"

    Tuesday, January 13, 2015 6:57 AM
  • Few years back i have made it to practice on small basic programming. This program uses offset of 18 charactes. Here is program code and its output

    '65 to 90 are uppercase characters while 97 to 122 are lower case characters
    'this program encrypts the private message
    '=================================================
    TextWindow.ForegroundColor = "Cyan"
    TextWindow.WriteLine("Enter message to be sent it privatly")
    TextWindow.WriteLine("Entered message will be encrypted and displayed")
    TextWindow.WriteLine("If this encrypted message entered")
    TextWindow.WriteLine("You have to use other program to show original message")
    TextWindow.WriteLine("==========================================================")
    TextWindow.WriteLine("")
    
    TextWindow.ForegroundColor = "Green"
    TextWindow.WriteLine("Enter a private message here -")
    TextWindow.WriteLine("")
    TextWindow.Write("Message - ? ")
    OriginalMsg = TextWindow.Read()
    
    For I = 1 To Text.GetLength(OriginalMsg)
      Chr = Text.GetSubText(OriginalMsg,I,1)
      ChrCode = Text.GetCharacterCode(Chr)
      
      'Process upper case
      If ChrCode > 64 And  ChrCode < 91 Then
        ChrCode = ChrCode + 18
        If ChrCode > 90 Then
          ChrCode = ChrCode - 26
        EndIf
      EndIf
    
      'Process lower case
      If ChrCode > 96 And  ChrCode < 123 Then
        ChrCode = ChrCode + 18
        If ChrCode > 122 Then
          ChrCode = ChrCode - 26
        EndIf
      EndIf
      ChrNew = Text.GetCharacter(ChrCode)
      EncryptedMsg = Text.Append(EncryptedMsg,ChrNew)
    EndFor
    
    TextWindow.ForegroundColor = "Red"
    TextWindow.WriteLine("")
    TextWindow.Write("Encrypted Message - ")
    TextWindow.WriteLine(EncryptedMsg)
    
    

    Here is program output

    Also there is decrypt code as here

    '65 to 90 are uppercase characters while 97 to 122 are lower case characters
    'this program decrypts the private message
    '=================================================
    TextWindow.ForegroundColor = "Cyan"
    TextWindow.WriteLine("Enter encrypted message receivd")
    TextWindow.WriteLine("Entered message will be decrypted and displayed as original")
    TextWindow.WriteLine("==========================================================")
    TextWindow.WriteLine("")
    
    TextWindow.ForegroundColor = "Red"
    TextWindow.WriteLine("Enter a private message here -")
    TextWindow.WriteLine("")
    TextWindow.Write("Message - ? ")
    EncryptedMsg = TextWindow.Read()
    
    For I = 1 To Text.GetLength(EncryptedMsg)
      Chr = Text.GetSubText(EncryptedMsg,I,1)
      ChrCode = Text.GetCharacterCode(Chr)
      
      'Process upper case
      If ChrCode > 64 And  ChrCode < 91 Then
        ChrCode = ChrCode - 18
        If ChrCode < 65 Then
          ChrCode = ChrCode + 26
        EndIf
      EndIf
    
      'Process lower case
      If ChrCode > 96 And  ChrCode < 123 Then
        ChrCode = ChrCode - 18
        If ChrCode < 97 Then
          ChrCode = ChrCode + 26
        EndIf
      EndIf
      ChrNew = Text.GetCharacter(ChrCode)
      OriginalMsg = Text.Append(OriginalMsg,ChrNew)
    EndFor
    
    TextWindow.ForegroundColor = "Green"
    TextWindow.WriteLine("")
    TextWindow.Write("Encrypted Message - ")
    TextWindow.WriteLine(OriginalMsg)
    

    Here is output corresponding to previous encrypted message

    This may help you

    Wednesday, January 14, 2015 4:57 PM

All replies

  • fanter123, how about searching in forum with keyword such like "encrypt" ?

    You can select this forum to enter "Small Basic" in Forums text box.


    Nonki Takahashi

    Tuesday, January 13, 2015 5:01 AM
  • Hi fanter123

    To do this you can use the operations of Text object.

    GetSubText, GetCharacterCode and GetCharacter. Add then subtract an offset to encrypt and decipher the characters of the plain text and encryption.

    Textboxes would be handy since you can copy/paste in them.

    Using a simple literal offset like this would make the encryption unreadable but very easy to crack! More sophisticated algorithms are used for sensitive data. A simple offset might suitable for not so sensitive data.

    There's a SB extension that encrypts plain text.

    Text.GetCharacterCode("a") + 100 = Encrypted "a"

    Tuesday, January 13, 2015 6:57 AM
  • Few years back i have made it to practice on small basic programming. This program uses offset of 18 charactes. Here is program code and its output

    '65 to 90 are uppercase characters while 97 to 122 are lower case characters
    'this program encrypts the private message
    '=================================================
    TextWindow.ForegroundColor = "Cyan"
    TextWindow.WriteLine("Enter message to be sent it privatly")
    TextWindow.WriteLine("Entered message will be encrypted and displayed")
    TextWindow.WriteLine("If this encrypted message entered")
    TextWindow.WriteLine("You have to use other program to show original message")
    TextWindow.WriteLine("==========================================================")
    TextWindow.WriteLine("")
    
    TextWindow.ForegroundColor = "Green"
    TextWindow.WriteLine("Enter a private message here -")
    TextWindow.WriteLine("")
    TextWindow.Write("Message - ? ")
    OriginalMsg = TextWindow.Read()
    
    For I = 1 To Text.GetLength(OriginalMsg)
      Chr = Text.GetSubText(OriginalMsg,I,1)
      ChrCode = Text.GetCharacterCode(Chr)
      
      'Process upper case
      If ChrCode > 64 And  ChrCode < 91 Then
        ChrCode = ChrCode + 18
        If ChrCode > 90 Then
          ChrCode = ChrCode - 26
        EndIf
      EndIf
    
      'Process lower case
      If ChrCode > 96 And  ChrCode < 123 Then
        ChrCode = ChrCode + 18
        If ChrCode > 122 Then
          ChrCode = ChrCode - 26
        EndIf
      EndIf
      ChrNew = Text.GetCharacter(ChrCode)
      EncryptedMsg = Text.Append(EncryptedMsg,ChrNew)
    EndFor
    
    TextWindow.ForegroundColor = "Red"
    TextWindow.WriteLine("")
    TextWindow.Write("Encrypted Message - ")
    TextWindow.WriteLine(EncryptedMsg)
    
    

    Here is program output

    Also there is decrypt code as here

    '65 to 90 are uppercase characters while 97 to 122 are lower case characters
    'this program decrypts the private message
    '=================================================
    TextWindow.ForegroundColor = "Cyan"
    TextWindow.WriteLine("Enter encrypted message receivd")
    TextWindow.WriteLine("Entered message will be decrypted and displayed as original")
    TextWindow.WriteLine("==========================================================")
    TextWindow.WriteLine("")
    
    TextWindow.ForegroundColor = "Red"
    TextWindow.WriteLine("Enter a private message here -")
    TextWindow.WriteLine("")
    TextWindow.Write("Message - ? ")
    EncryptedMsg = TextWindow.Read()
    
    For I = 1 To Text.GetLength(EncryptedMsg)
      Chr = Text.GetSubText(EncryptedMsg,I,1)
      ChrCode = Text.GetCharacterCode(Chr)
      
      'Process upper case
      If ChrCode > 64 And  ChrCode < 91 Then
        ChrCode = ChrCode - 18
        If ChrCode < 65 Then
          ChrCode = ChrCode + 26
        EndIf
      EndIf
    
      'Process lower case
      If ChrCode > 96 And  ChrCode < 123 Then
        ChrCode = ChrCode - 18
        If ChrCode < 97 Then
          ChrCode = ChrCode + 26
        EndIf
      EndIf
      ChrNew = Text.GetCharacter(ChrCode)
      OriginalMsg = Text.Append(OriginalMsg,ChrNew)
    EndFor
    
    TextWindow.ForegroundColor = "Green"
    TextWindow.WriteLine("")
    TextWindow.Write("Encrypted Message - ")
    TextWindow.WriteLine(OriginalMsg)
    

    Here is output corresponding to previous encrypted message

    This may help you

    Wednesday, January 14, 2015 4:57 PM
  • Came across a Ceasar encrypt/decrypt code on a C# site this weekend and freely converted them to SB.

    Original links included. 'CaesarEnDecrypt' ID: PKN575

    Monday, January 19, 2015 8:40 PM
    Answerer