Author Topic: encrypt decrypt project  (Read 6610 times)

0 Members and 1 Guest are viewing this topic.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
encrypt decrypt project
« on: March 10, 2021, 11:12:59 pm »
OK this is sloppy but works! :-)
This is based off the Vigenère cipher (however you pronouce that)
Details:
So I wanted to play a little FFXIV and found I had 6hrs to kill, so wasted about 3hrs just looking for a simple encrypt/decrypt qb code - nothing really to be found. There is one here but other than that there were rare. weird - many other languages had one, but could not find a simple encode/decode. the closes I could find was a python one that was pretty simple, however, took a bit to convert. So you will have to pardon the naming convention I used LOL,
Anyways. thought I would post it here. someone can tidy it up if they like.

Code: QB64: [Select]
  1. Function str_encode$ (salt As String, pw As String, method As String)
  2.     Dim m, cnt As Integer
  3.     Dim k, I As Integer
  4.     Dim pw1 As String
  5.     Dim pw2 As String
  6.     Dim l As String
  7.  
  8.     pw2 = ""
  9.     For I = 1 To Len(pw)
  10.         m = I Mod Len(salt)
  11.  
  12.         pw1 = Mid$(salt, m, 1)
  13.         k = (m Mod 256)
  14.         If method = "e" Then
  15.             l = Chr$(Asc(Mid$(pw, I, 1)) + k)
  16.         Else
  17.             l = Chr$(Asc(Mid$(pw, I, 1)) - k)
  18.         End If
  19.         pw2 = pw2 + l
  20.  
  21.     Next
  22.     str_encode$ = pw2

Pretty self explanatory.
Send a "key" or "salt", and your password. and it will encrypt it.
usage
some_string_var = str_encode(salt, pw, [e or blank for decode])



I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: encrypt decrypt project
« Reply #1 on: March 11, 2021, 02:13:49 am »
For starters, I had to lookup "FFXIV"... That's my age showing... lol

Cipher / Decipher is totally, what's the phrase, above my pay grade... lol  Just curious as to why you would want / need a program like this one...

By the way... I like your "quote"... Cool...
Logic is the beginning of wisdom.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: encrypt decrypt project
« Reply #2 on: March 11, 2021, 07:08:08 am »
For starters, I had to lookup "FFXIV"... That's my age showing... lol

Cipher / Decipher is totally, what's the phrase, above my pay grade... lol  Just curious as to why you would want / need a program like this one...

By the way... I like your "quote"... Cool...

LOL!!!
don't single yourself out so fast  - IM 56 (at the time of this writing for future visitors and my kids are in their 30's). I'm just a big kid at heart when I am not working, and sometimes when I am :-), aside from programing I am a huge gamer - steam alone I have 1,000+, however my A.D.D. prevents me from finishing most of them. Even built my own DDR board - was heavily addicted to that thing. to some pretty large MMO back ends (World of Warcraft being my main one), and many minecraft apps as well as a back-end for that one as well. I really hate buying software hahaha.

As far as why I would need a program like this? I spent my years writing software for myself, not commercial. It started when I got my first "computer" TIMEX SINCLAIR  1K ram!!! haha! And I wanted a nice Rolodex - that's what we called "contacts" back in the day. Obviously nothing really available for a kid like me, so I wrote one, then wrote a simple text adventure. These days, I have written my own subtitle maker (vb6) several basic text games (pascal and qbasic) and so forth. Which is why I like qb64 - it keeps me close to my golden days of DOS games and apps.

Today, with last-pass being stupid, I am thinking, I do not need that powerful of a PW manager. so making my own. that's where this simple little encrypt/decrypt comes in. Its not perfect but does the job. And my id/pw are stored on my system not someone else's PC in the cloud. Its not fancy, with all the auto stuff, but at least I works. And now that QB64 can do android (I think) I might extend this so I can use it on my phone.

ok that was a lot, but too lazy to erase it :P



« Last Edit: March 11, 2021, 07:16:30 am by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: encrypt decrypt project
« Reply #3 on: March 11, 2021, 08:12:09 am »
Example from my pw mgr app. creating an account will produce the following (accounts.txt)

Quote
24;4?xpsrDaq‚NWF{QHK^J\f~<KDLAv:zq\W


This string holds the id, pw, and key all it one
if someone has a handy brute force app. try to crack it.
2 more hints: both pw/id are 4 char long in this example. I am pretty confident this is pretty solid. I actually use a method that is used in logins for WoW private servers.

Anyways.. for personal use my pw mgr will do just fine for me :-)
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: encrypt decrypt project
« Reply #4 on: March 11, 2021, 10:38:54 pm »
My first InForm Project was Cryptogram now lost I suppose when forum reshuffled the boards.

I don't know what you call the method of my encryption it randomly assigned symbols to other symbols and then shifted the table 1 or more places on each letter so you couldn't break it by counting letters and doing stats.

I just rewrote a simple version:
Code: QB64: [Select]
  1. _Title "Cryptogram" ' revisited b+ 2021-03-11
  2.  
  3. ReDim Shared L$, ABC$
  4.     Input "Enter a seed number "; sd
  5.     StartCoder sd
  6.     secret$ = encode$("Here is my secret.")
  7.     Print "   Coded: "; secret$
  8.     Print " Decoded: "; decode$(secret$)
  9.     Print
  10.     Sleep
  11.     Cls
  12.  
  13. Function encode$ (CodeThis$)
  14.     code$ = L$
  15.     For i = 1 To Len(CodeThis$)
  16.         If Asc(CodeThis$, i) > 31 And Asc(CodeThis$, i) < 128 Then
  17.             encode$ = encode$ + Mid$(code$, InStr(ABC$, Mid$(CodeThis$, i, 1)), 1)
  18.         Else
  19.             encode$ = encode$ + Mid$(CodeThis$, i, 1)
  20.         End If
  21.         code$ = Mid$(code$, 2) + Mid$(code$, 1, 1) 'so can't break code by char counts
  22.     Next
  23.  
  24. Function decode$ (This$)
  25.     code$ = L$
  26.     For i = 1 To Len(This$)
  27.         If Asc(This$, i) > 31 And Asc(This$, i) < 128 Then
  28.             place = InStr(code$, Mid$(This$, i, 1))
  29.             decode$ = decode$ + Chr$(place + 31)
  30.         Else
  31.             decode$ = decode$ + Mid$(This$, i, 1)
  32.         End If
  33.         code$ = Mid$(code$, 2) + Mid$(code$, 1, 1) 'so can't break code by char counts
  34.     Next
  35.  
  36. Sub StartCoder (seed As Single)
  37.     Randomize Using seed
  38.     L$ = "" 'ha! When you share it, you have to reinitialize it
  39.     For i = 32 To 127
  40.         L$ = L$ + Chr$(i)
  41.     Next
  42.     ABC$ = L$
  43.     'shuffle string
  44.     For i = Len(L$) To 2 Step -1
  45.         r = Int(i * Rnd) + 1
  46.         t$ = Mid$(L$, i, 1)
  47.         Mid$(L$, i, 1) = Mid$(L$, r, 1)
  48.         Mid$(L$, r, 1) = t$
  49.     Next
  50.  
  51.  

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: encrypt decrypt project
« Reply #5 on: March 12, 2021, 05:07:50 pm »
One of the things that the WOW private servers did , and not sure this is true for the retail end, but they used a md5(), but instead of straigh md5(pw) it was always mixed with id so your

Code: PHP: [Select]
  1.  pw =  md5(strtoupper(pw.":".id))

using this method, even the most simplest encryption becomes a little more difficult to decrypt.

Code: QB64: [Select]
  1. pw = encode pw+":"+id

speaking of, has QB64 incorporated any internal hash keywords yet? sha1,md5 etc...?

« Last Edit: March 12, 2021, 05:11:00 pm by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: encrypt decrypt project
« Reply #6 on: March 12, 2021, 06:29:03 pm »
Hi Xra7en
here my old encrypt/decript that use a simple sostitution method 1 by 1
https://www.qb64.org/forum/index.php?topic=281.0
it has been coded into Inform, but the core can be extracted to be one function.
And with little work it can be powered into a 1 to many sostituions with a key to encrypt/decrypt
Thanks to read
Programming isn't difficult, only it's  consuming time and coffee

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: encrypt decrypt project
« Reply #7 on: March 12, 2021, 10:45:25 pm »
How do you distribute the key securely?

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: encrypt decrypt project
« Reply #8 on: March 12, 2021, 11:11:52 pm »
How do you distribute the key securely?

can you elaborate on "distribute"?

I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: encrypt decrypt project
« Reply #10 on: March 13, 2021, 06:15:10 am »
Print it on a piece of paper and include it with the software packaging, or send a verification e-mail at registration time.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: encrypt decrypt project
« Reply #11 on: March 13, 2021, 07:53:33 am »
oooooo
 der!!

This is a private project - there is no distribution.

When you start the app, it creates a key. It is not saved anywhere other than where I keep it.
To login to the app needs the id/pw and the key. Loose the key and you cannot access the app. Loose the key and you cannot access your data, as the key is used to encrypt the data as well.

It is a private password manager I am working on. So far it is pretty nice. Hopefully later down the road I can figure out how to make it work on android :-)
I'll prob post the code here when do so others can play with it.

I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: encrypt decrypt project
« Reply #12 on: March 13, 2021, 11:06:16 am »
How do you distribute the key securely?

Print it on a piece of paper and include it with the software packaging, or send a verification e-mail at registration time.

While xra7en gets his stuff together, Steve's answer will work fine for the demo I offered in this thread.

PM me or anyone and share pass codes and send each other coded messages.

If you are afraid this is too easy to crack use a Shared bookpage say from a public document to shift the table variable amounts instead of just one all the time.

There are tons and tons of ways to make it even harder, I pity the code crackers task ;-))

Check out RSA on Internet for Public sharing of coded messages.
« Last Edit: March 13, 2021, 11:15:22 am by bplus »

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: encrypt decrypt project
« Reply #13 on: March 13, 2021, 11:35:48 am »
my app does not have (or need) a distro

so unsure what I need to get together? Unless my thread just got hi-jacked and missed the branch :-P
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: encrypt decrypt project
« Reply #14 on: March 13, 2021, 11:50:14 am »
my app does not have (or need) a distro

so unsure what I need to get together? Unless my thread just got hi-jacked and missed the branch :-P


Sorry, the thread says encrypt decrypt didn't mean to hi-jack. I thought I was completing the thought about encryption decryption you left unfinished.

But then I have to say it is not clear to me what your project is about.

And I suggest you post project code in Programs Board so it's not mistaken as a discussion or a question.
« Last Edit: March 13, 2021, 12:11:43 pm by bplus »