# PureBasic Forum

 It is currently Wed Nov 25, 2020 2:38 am

 All times are UTC + 1 hour

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: simple text encryptionPosted: Sun Jan 11, 2004 1:01 am
 User

Joined: Mon Apr 28, 2003 8:49 pm
Posts: 30
Code updated For 5.20+

Maybe useful for someone.

include:
Code:
Procedure CalculateSeed(InputNumber)
ProcedureReturn Int(Log(InputNumber) * Cos(InputNumber) * 137)
EndProcedure

For i = 1 To Len(Password)
ASCII_Vals = ASCII_Vals + Asc(Mid(Password, i, 1))
Next i

ProcedureReturn Int(CalculateSeed(ASCII_Vals) / CalculateSeed(Len(Password) + 1))
Else
ProcedureReturn CalculateSeed(ASCII_Vals)
EndIf
EndProcedure

Procedure WrapNumber(lngNumber, lngMinimum, lngMaximum)
Define Range, check
Range = lngMaximum - lngMinimum
check = lngNumber

If lngNumber > lngMaximum
Repeat
check = check - Range
Until check <= lngMaximum
ElseIf lngNumber < lngMinimum
Repeat
check = check + Range
Until check >= lngMinimum
EndIf
ProcedureReturn check
EndProcedure

enctxt.s

CurrentMod = 2

For i = 1 To Len(Input)
CurrentChar = Asc(Mid(Input, i, 1))
CurrentChar = CurrentChar - CalculateSeed(CurrentMod)
CurrentChar = WrapNumber(CurrentChar, 0, 255)
enctxt = enctxt + Chr(CurrentChar)
CurrentMod = CurrentMod + 1

If CurrentMod > 30
CurrentMod = 2
EndIf
Next i
ProcedureReturn enctxt
EndProcedure

dectxt.s
CurrentMod = 2

For i = 1 To Len(Input)
CurrentChar = Asc(Mid(Input, i, 1))
CurrentChar = CurrentChar + CalculateSeed(CurrentMod)
CurrentChar = WrapNumber(CurrentChar, 0, 255)
dectxt = dectxt + Chr(CurrentChar)
CurrentMod = CurrentMod + 1

If CurrentMod > 30
CurrentMod = 2
EndIf
Next i
ProcedureReturn dectxt
EndProcedure

a little example.
main:
Code:
; PureBasic Visual Designer v3.82 build 1354

IncludeFile "Common.pb"
IncludeFile "Procedures.pbi"

Open_Window_0()

Repeat

Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1

Case #Button_0  ;Encrypt
Else
StatusBarText(#StatusBar_0, 0, "invisible character/s found, please use another pw.")
Else
StatusBarText(#StatusBar_0, 0, "Encryption successful!")
EndIf
EndIf
Case #Button_1  ;Decrypt
Else
StatusBarText(#StatusBar_0, 0, "Decryption succesful!")
EndIf
Case #String_1  ; Input
If EventType() = #PB_EventType_Change
EndIf
Case #String_2  ; Output
If EventType() = #PB_EventType_Change
EndIf
EndSelect
EndIf

Until Quit

End

common:
Code:
; PureBasic Visual Designer v3.82 build 1354

;- Window Constants
;
Enumeration
#Window_0
EndEnumeration

;
Enumeration
#Text_0
#String_0
#String_1
#Text_1
#Button_0
#Button_1
#String_2
#StatusBar_0
EndEnumeration

;- Fonts
;
Global FontID1
FontID1 = LoadFont(1, "Arial", 10, #PB_Font_Bold)
Global FontID2
FontID2 = LoadFont(2, "Arial", 8, #PB_Font_Bold)

Procedure Open_Window_0()
If OpenWindow(#Window_0, 433, 212, 322, 370 , "Text-Crypt",  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
If CreateStatusBar(#StatusBar_0, WindowID(#Window_0))
EndIf

EditorGadget(#String_1, 20, 70, 280, 100, #ES_AUTOVSCROLL|#WS_VSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT)
TextGadget(#Text_1, 48, 50, 45, 15, "Input:")
ButtonGadget(#Button_0, 20, 180, 280, 30, "Encrypt")
ButtonGadget(#Button_1, 20, 210, 280, 30, "Decrypt")
EditorGadget(#String_2, 20, 250, 280, 100, #ES_AUTOVSCROLL|#WS_VSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT)
;         EndIf
EndIf
EndProcedure

Manne

Top

 Post subject: Re: simple text encryptionPosted: Fri Nov 20, 2020 8:35 am

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1170
Location: Portugal
Thanks for sharing.

Easy to use and I am using it to encrypt my passwords etc.

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.

Top

 Post subject: Re: simple text encryptionPosted: Sat Nov 21, 2020 9:49 am

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4790
Location: Lyon - France
2004 always works here with 5.72
Not see before, a "little bit" late thanks for sharing

_________________
Not a destination

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 44 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite