decoder message demo

New to FreeBASIC? Post your questions here.
ron77
Posts: 197
Joined: Feb 21, 2019 19:24
Location: Israel
Contact:

decoder message demo

Postby ron77 » Mar 08, 2021 16:21

hello...

here is a code of an encoded message in DATA structure with it's decoder code when you'll run the code it will decode the message and print it to the screen... just a small demo...

ron77

Code: Select all

SCREEN 19

Const string1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Const string2 = "VsciBjedgrzyHalvXZKtUPumGfIwJxqOCFRApnDhQWobLkESYMTN"

REDIM AS STRING message(0)
DIM AS STRING r

SUB sAppend(arr() AS STRING , Item AS STRING)
   REDIM PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
   arr(UBOUND(arr)) = Item
END SUB

FOR i AS INTEGER = 0 TO 27
   READ r
   SAPPEND(message(), r)
NEXT

SUB encode_decode(arr() AS STRING)
   Dim s As String
   Dim p As INTEGER
   Dim As String vector, key
   
   vector = string2 : key = string1
   DIM currentChar AS INTEGER
   FOR i AS INTEGER = 0 TO UBOUND(arr)
      FOR x AS INTEGER = 1 TO LEN(arr(i))
      currentChar = ASC(MID(arr(i), x, 1))

      IF (currentChar >= 65 AND currentChar <= 90) OR (currentChar >= 97 AND currentChar <= 122) THEN
        p = INSTR(vector, MID(arr(i), x, 1))
        MID(arr(i), x, 1) = MID(key, p, 1)
      END IF
   
    NEXT     
     
   NEXT
   
   FOR i AS INTEGER = 0 TO UBOUND(arr)
      PRINT arr(i)
   NEXT
   
   
END SUB

encode_decode(message())



SLEEP




DATA "kqLkRhC kqLkRhC Qhq kYQ kFbqq OQEb"
DATA "kFRL RL Ih qhJQxqx kqMk DqLLICq OQb kqLkRhC kFq qhJQxqb xqJQxqb JQxq"
DATA "Qhq WnEL Qhq RL kYQ kqh DEnkRWnT wT kqh RL Qhq FEhxbqx..."
DATA" R FQWq R xQh'k FISq LWqnnRhC DRLkIpqL..."
DATA "kQxIT YIL I wqIEkROEn xIT YRkF YIbD YqIkFqb Ihx LEhhT LpT"
DATA "Rk'L ORSq OQEb-kFT qRCFk WD Fqbq Ihx kFq LEh AELk Lqk"
DATA "YFQqSqb TQE Ibq Ihx YFIk qSqb TQEb xQRhC R FQWq Ihx YRLF TQE Yqnn"
DATA "DIT Yq Inn JQhkRhEq kQ nqIbh Ihx WbQCbqLL Rh QEb YIT Rh nROq"
DATA "DIT Yq Inn nqIbh kQ wq wqkkqb JQxqbL Ihx WbQCbIDDqbL Rh YFIkqSqb"
DATA "WbQCbIDDRhC nIhCEICq Yq JFQQLq kQ nqIbh... DIT kFq js JQDDEhRkT"
DATA "LFqnn JQhkRhEq kQ qSQnSq Ihx LkIT bqnqSIhk Rh kFq WbQCbIDDRhC nIhCEICqL"
DATA "R LkRnn JQxq Rh js IL Yqnn QkFqb nIhCEICqL Ihx qSqbTxIT R nqIbh LQDqkFRhC hqY"
DATA "qSqbTxIT R JQxq LQDqkFRhC hqY Qb YQbp Qh LQDqkFRhC Rh JQxq"
DATA "JQxRhC RL Ih qMJqnnqhk YIT kQ OQbCqk kbQEwnqL Ihx YQbbRqL QO qSqbT xIT'L nROq"
DATA "R FQWq LQDqxIT kFq JQbQhI Qb JQSRx WIhxqDRJ YRnn wq wqFRhx EL Inn"
DATA "kRnn kFqh R FQWq Yq Inn LkIT FqInkFT LIOq Ihx WbQkqJkqx..."
DATA "Ihx LkIT Rh kQEJF YRkF QEb nQSqx QhqL... Ihx FqnW qIJF QkFqb"
DATA "YFIk qnLq JIh R LIT - R xQh'k phQY..."
DATA "R'Sq xqJRxqx kQ pqqW I nQY WbQORnq Rh kFq WbQCbIDDRhC JQDDEhRkRqL R'D WIbk QO"
DATA "FQYqSqb R LkRnn ID JQxRhC Ihx FQWq kQ wq Iwnq kQ JQhkbRwEkq kQ js JQDDEhRkT"
DATA "R'Sq kbRqx QkFqb sVKgc nIhCEICqL IL Yqnn R'D JQhkRhERhC kQ nqIbh WTkFQh"
DATA "wEk R Oqqn FQDq Ik js Ihx LRhJq R'Sq nqIbhqx LQ DEJF IwQEk Rk Rk YQEnx"
DATA "wq I LFIDq kQ AELk LkQW Ihx oERk qSqbTkFRhC R'Sq nqIbhqx LQ OIb Rh js"
DATA "LQ R'D JQhkRhERhC YRkF js...RO kFqbq RL LQDqkFRhC R'Sq nqIbhqx ObQD kFq nILk TqIb"
DATA "Rk'L kFIk R xQh'k Lqqp kQ ORhx ObRqhxL Qb kQ xQ kFq LQJRInRNRhC kFRhC"
DATA "R'D AELk nQQpRhC kQ nqIbh FQY kQ RDWbQSq DT JQxRhC LpRnnL Ihx kQ pqqW DTLqnO QJJEWRqx"
DATA "DT xqIb bqIxqb R YRLF TQE Yqnn Ihx OIbqYqnn... DITwq Yq LFqnn Dqqk LQDqxIT LQDq LEhhT xIT"
DATA "TQEbL - bQh77"

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 9 guests