BinaryKey - Module / HexaKey - Module

Share your advanced PureBasic knowledge/code with the community.
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

BinaryKey - Module / HexaKey - Module

Post by StarBootics »

Hello everyone,

A small code to manipulate Binary codes. It's possible than I get inspiration from other's codes, I can't tell how many.
Also a similar sets of procedures to deal with Hexa codes

Best regards
StarBootics

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : BinaryKey - Module
; File Name : BinaryKey - Module.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 14-02-2015
; Last Update : 27-01-2016
; PureBasic code : V5.41 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; This code was originally created by me to 
; explore some Crop Circle binary code and 
; some Messages apparently from Extra-Terrestrials.
;
; This code is free to be use where ever you like 
; but you use it at your own risk.
;
; The author can in no way be held responsible 
; for data loss, damage or other annoying 
; situations that may occur.
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule BinaryKey
  
  Declare.s Encode(Input.s)
  Declare.s Decode(Input.s)
  
EndDeclareModule

Module BinaryKey
  
  Procedure.s Encode(Input.s)
    
    For CharID = 1 To Len(Input)
      Output.s + RSet(Bin(Asc(Mid(Input, CharID, 1))), 8, "0")
    Next 
    
    ProcedureReturn Output
  EndProcedure
  
  Procedure.s Decode(Input.s)
    
    For CharID = 1 To Len(Input) Step 8
      Output.s + Chr(Val("%" + Mid(Input, CharID, 8)))
    Next
    
    ProcedureReturn Output
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  Macro AddElementEx(ListName, Element)
    AddElement(ListName)
    ListName = Element
  EndMacro
  
  Message.s = "EXPLORATION OF HUMANITY 666 8100" + #LF$
  Message + "52.0942532N 13.131269W" + #LF$
  Message + "CONTINUOUS FOR PLANETARY ADVANCEMENT" + #LF$
  Message + "FOURTH COODINATE CONTINUOT UQS CbPR BEFORE" + #LF$
  
  Debug BinaryKey::Encode(Message)
  Debug ""
  
  Message2.s = "Beware the bearers of false gifts & broken promises" ;+ #LF$
  Message2 + "Much pain but still time" ;+ #LF$
  Message2 + "There is good out there" ;+ #LF$
  Message2 + "We opose deception" ;+ #LF$
  Message2 + "Conduit closing"
  
  Debug BinaryKey::Encode(Message2)
  
  ; ­­­<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ; The following example came from this video :
  ; https://www.youtube.com/watch?v=3rXr7pqJ92g
  
  NewList BinCode.s()
  
  AddElementEx(BinCode(), "01000101")
  AddElementEx(BinCode(), "01100001")
  AddElementEx(BinCode(), "01000101")
  AddElementEx(BinCode(), "01101110")
  AddElementEx(BinCode(), "01101011")
  AddElementEx(BinCode(), "01101001")
  AddElementEx(BinCode(), "00100000")
  
  ForEach BinCode()
    Message3.s + BinaryKey::Decode(BinCode())
  Next
  
  Debug Message3

CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : HexaKey - Module
; File Name : HexaKey - Module.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : StarBootics
; Date : 07-07-2012
; Last Update : 27-01-2016
; PureBasic code : V5.41 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; This code was originally created by an unknown
; author. 
;
; I deserve credit only to convert the original 
; code into a Module.
;
; This code is free to be use where ever you like 
; but you use it at your own risk.
;
; The author can in no way be held responsible 
; for data loss, damage or other annoying 
; situations that may occur.
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule HexaKey
  
  Declare.s Decode(Pass.s)
  Declare.s Encode(Pass.s)
  
EndDeclareModule

Module HexaKey
  
  Procedure.s Decode(Pass.s)
    
    PassLen = Len(Pass)
    
    For CharID = 1 To PassLen Step 2
      Decoded.s = Decoded + Chr(Val("$" + Mid(Pass, CharID, 2)))
    Next
    
    ProcedureReturn Decoded
  EndProcedure
  
  Procedure.s Encode(Pass.s)
    
    PassLen = Len(Pass)
    
    For CharID = 1 To PassLen
      Encoded.s = Encoded + Hex(Asc(Mid(Pass, CharID, 1)))
    Next
    
    ProcedureReturn Encoded
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  Encode.s = HexaKey::Encode("PureBasic V5.41 LTS")
  Decode.s = HexaKey::Decode(Encode)
  
  Debug Encode
  Debug Decode
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
The Stone Age did not end due to a shortage of stones !