Encryption Algorithm

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Encryption Algorithm

Postby Lyberodoggy » Sat Apr 05, 2008 6:26 pm

Here's a code to transform "a" to "e" and so on in the alphabet. It's based on a puzzle in "Safe Cracker" remake...
Here it goes:
Code: Select all
A=InputBox("Input a phrase")
I=0
Do Until I=Len(A)
I=I+1
B=lcase(Mid(A,I,1))
Select Case B
Case "a"
B="e"
Case "b"
B="f"
Case "c"
B="g"
Case "d"
B="h"
Case "e"
B="i"
Case "f"
B="j"
Case "g"
B="k"
Case "h"
B="l"
Case "i"
B="m"
Case "j"
B="n"
Case "k"
B="o"
Case "l"
B="p"
Case "m"
B="q"
Case "n"
B="r"
Case "o"
B="s"
Case "p"
B="t"
Case "q"
B="u"
Case "r"
B="v"
Case "s"
B="w"
Case "t"
B="x"
Case "u"
B="y"
Case "v"
B="z"
Case "w"
B="a"
Case "x"
B="b"
Case "y"
B="c"
Case "z"
B="d"
End Select
C=C+B
Loop
MsgBox C


And the decryption:

Code: Select all
A=InputBox("Input an encrypted phrase")
I=0
Do Until I=Len(A)
I=I+1
B=lcase(Mid(A,I,1))
Select Case B
Case "e"
B="a"
Case "f"
B="b"
Case "g"
B="c"
Case "h"
B="d"
Case "i"
B="e"
Case "j"
B="f"
Case "k"
B="g"
Case "l"
B="h"
Case "m"
B="i"
Case "n"
B="j"
Case "o"
B="k"
Case "p"
B="l"
Case "q"
B="m"
Case "r"
B="n"
Case "s"
B="o"
Case "t"
B="p"
Case "u"
B="q"
Case "v"
B="r"
Case "w"
B="s"
Case "x"
B="t"
Case "y"
B="u"
Case "z"
B="v"
Case "a"
B="w"
Case "b"
B="x"
Case "c"
B="y"
Case "d"
B="z"
End Select
C=C+B
Loop
MsgBox C


Hope you like this one!
Last edited by Lyberodoggy on Tue Apr 20, 2010 10:17 pm, edited 1 time in total.
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Chromegloss55 » Tue Apr 22, 2008 7:31 pm

Nobody has given you much credit on this...

(Probably because not many people know what's going on)

It's pretty good... maybe just not versatile enough...
_________________
Marriage Advice Forum
Last edited by Chromegloss55 on Tue Feb 24, 2009 3:14 pm, edited 1 time in total.
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!

Postby cpkspikyhair » Tue Apr 22, 2008 8:49 pm

That would be necessary for a puzzle game...Great Job :D !
PSPPC GameMaker!! Where you can find PSP and PC games up for download!
User avatar
cpkspikyhair
Games Page Administrator
 
Posts: 425
Joined: Thu Jun 28, 2007 1:49 pm
Location: On Mars (Yes There Is Water :) )

Postby Lyberodoggy » Wed Apr 23, 2008 7:45 am

Thanks guys! By not versatile you probably mean that it only converts the text with the base of "e"... Well I 've created another version of the code which allows you to create encrypted text based on any letter and I 'm going to create phrase-based encryption at some time.


What the other code actually does is connecting every letter with a number from 1 to 26.

Well, I 'm attaching it, though I wasn't going to, because it will help lots of people
WARNING! This is only for use with AM. You are not allowed to use this code in a (non-)commercial programm but you can use it in any game created with AM either commercial or non-commercial and I just want my name in the credits, nothing else. Bare in mind that this code is reserved and originally used by one of my programs, Burnt Pixel's SafeSys
Code: Select all
    Dim notvalid As Boolean
Private Sub Encryption
        Dim A As String
        Dim B As String
        Dim C As String
        Dim I As Integer
        Dim letter As String
        letter = txt2.Text
        getletternum(letter)
        If notvalid = 1 Then
            Exit Sub
        End If
        If encrypt = True Then
            A = txt1.Text
            I = 0
            I = 0
            Do Until I = Len(A)
                I = I + 1
                B = LCase(Mid(A, I, 1))
                Select Case B
                    Case "a"
                        B = getletterfromnum(getletternum(letter))
                    Case "b"
                        B = getletterfromnum(getletternum(letter) + 1)
                    Case "c"
                        B = getletterfromnum(getletternum(letter) + 2)
                    Case "d"
                        B = getletterfromnum(getletternum(letter) + 3)
                    Case "e"
                        B = getletterfromnum(getletternum(letter) + 4)
                    Case "f"
                        B = getletterfromnum(getletternum(letter) + 5)
                    Case "g"
                        B = getletterfromnum(getletternum(letter) + 6)
                    Case "h"
                        B = getletterfromnum(getletternum(letter) + 7)
                    Case "i"
                        B = getletterfromnum(getletternum(letter) + 8)
                    Case "j"
                        B = getletterfromnum(getletternum(letter) + 9)
                    Case "k"
                        B = getletterfromnum(getletternum(letter) + 10)
                    Case "l"
                        B = getletterfromnum(getletternum(letter) + 11)
                    Case "m"
                        B = getletterfromnum(getletternum(letter) + 12)
                    Case "n"
                        B = getletterfromnum(getletternum(letter) + 13)
                    Case "o"
                        B = getletterfromnum(getletternum(letter) + 14)
                    Case "p"
                        B = getletterfromnum(getletternum(letter) + 15)
                    Case "q"
                        B = getletterfromnum(getletternum(letter) + 16)
                    Case "r"
                        B = getletterfromnum(getletternum(letter) + 17)
                    Case "s"
                        B = getletterfromnum(getletternum(letter) + 18)
                    Case "t"
                        B = getletterfromnum(getletternum(letter) + 19)
                    Case "u"
                        B = getletterfromnum(getletternum(letter) + 20)
                    Case "v"
                        B = getletterfromnum(getletternum(letter) + 21)
                    Case "w"
                        B = getletterfromnum(getletternum(letter) + 22)
                    Case "x"
                        B = getletterfromnum(getletternum(letter) + 23)
                    Case "y"
                        B = getletterfromnum(getletternum(letter) + 24)
                    Case "z"
                        B = getletterfromnum(getletternum(letter) + 25)
                End Select
                C = C + B
            Loop
            txt1.Text = C
        End If
        If decrypt = True Then
            A = txt1.Text
            I = 0
            Do Until I = Len(A)
                I = I + 1
                B = LCase(Mid(A, I, 1))
                Select Case B
                    Case getletterfromnum(getletternum(letter))
                        B = "a"
                    Case getletterfromnum(getletternum(letter) + 1)
                        B = "b"
                    Case getletterfromnum(getletternum(letter) + 2)
                        B = "c"
                    Case getletterfromnum(getletternum(letter) + 3)
                        B = "d"
                    Case getletterfromnum(getletternum(letter) + 4)
                        B = "e"
                    Case getletterfromnum(getletternum(letter) + 5)
                        B = "f"
                    Case getletterfromnum(getletternum(letter) + 6)
                        B = "g"
                    Case getletterfromnum(getletternum(letter) + 7)
                        B = "h"
                    Case getletterfromnum(getletternum(letter) + 8)
                        B = "i"
                    Case getletterfromnum(getletternum(letter) + 9)
                        B = "j"
                    Case getletterfromnum(getletternum(letter) + 10)
                        B = "k"
                    Case getletterfromnum(getletternum(letter) + 11)
                        B = "l"
                    Case getletterfromnum(getletternum(letter) + 12)
                        B = "m"
                    Case getletterfromnum(getletternum(letter) + 13)
                        B = "n"
                    Case getletterfromnum(getletternum(letter) + 14)
                        B = "o"
                    Case getletterfromnum(getletternum(letter) + 15)
                        B = "p"
                    Case getletterfromnum(getletternum(letter) + 16)
                        B = "q"
                    Case getletterfromnum(getletternum(letter) + 17)
                        B = "r"
                    Case getletterfromnum(getletternum(letter) + 18)
                        B = "s"
                    Case getletterfromnum(getletternum(letter) + 19)
                        B = "t"
                    Case getletterfromnum(getletternum(letter) + 20)
                        B = "u"
                    Case getletterfromnum(getletternum(letter) + 21)
                        B = "v"
                    Case getletterfromnum(getletternum(letter) + 22)
                        B = "w"
                    Case getletterfromnum(getletternum(letter) + 23)
                        B = "x"
                    Case getletterfromnum(getletternum(letter) + 24)
                        B = "y"
                    Case getletterfromnum(getletternum(letter) + 25)
                        B = "z"
                End Select
                C = C + B
            Loop
            txt1.Text = C
        End If
End Sub
Function getletternum(letter)
        notvalid = 0
        Select Case lcase(letter)
            Case "a"
                getletternum = 1
            Case "b"
                getletternum = 2
            Case "c"
                getletternum = 3
            Case "d"
                getletternum = 4
            Case "e"
                getletternum = 5
            Case "f"
                getletternum = 6
            Case "g"
                getletternum = 7
            Case "h"
                getletternum = 8
            Case "i"
                getletternum = 9
            Case "j"
                getletternum = 10
            Case "k"
                getletternum = 11
            Case "l"
                getletternum = 12
            Case "m"
                getletternum = 13
            Case "n"
                getletternum = 14
            Case "o"
                getletternum = 15
            Case "p"
                getletternum = 16
            Case "q"
                getletternum = 17
            Case "r"
                getletternum = 18
            Case "s"
                getletternum = 19
            Case "t"
                getletternum = 20
            Case "u"
                getletternum = 21
            Case "v"
                getletternum = 22
            Case "w"
                getletternum = 23
            Case "x"
                getletternum = 24
            Case "y"
                getletternum = 25
            Case "z"
                getletternum = 26
            Case Else
                MsgBox("Please enter a valid english character as a base for encryption", vbCritical)
                notvalid = 1
                getletternum = 1
        End Select

End Function

Function getletterfromnum(num)
        Dim sth As Integer
        sth = num
        If sth > 26 Then
            sth = sth - 26
        End If
        Select Case sth
            Case 1
                getletterfromnum = "a"
            Case 2
                getletterfromnum = "b"
            Case 3
                getletterfromnum = "c"
            Case 4
                getletterfromnum = "d"
            Case 5
                getletterfromnum = "e"
            Case 6
                getletterfromnum = "f"
            Case 7
                getletterfromnum = "g"
            Case 8
                getletterfromnum = "h"
            Case 9
                getletterfromnum = "i"
            Case 10
                getletterfromnum = "j"
            Case 11
                getletterfromnum = "k"
            Case 12
                getletterfromnum = "l"
            Case 13
                getletterfromnum = "m"
            Case 14
                getletterfromnum = "n"
            Case 15
                getletterfromnum = "o"
            Case 16
                getletterfromnum = "p"
            Case 17
                getletterfromnum = "q"
            Case 18
                getletterfromnum = "r"
            Case 19
                getletterfromnum = "s"
            Case 20
                getletterfromnum = "t"
            Case 21
                getletterfromnum = "u"
            Case 22
                getletterfromnum = "v"
            Case 23
                getletterfromnum = "w"
            Case 24
                getletterfromnum = "x"
            Case 25
                getletterfromnum = "y"
            Case 26
                getletterfromnum = "z"
        End Select
End Function


I 've corrected some things to adapt to vbs since this was taken from a VB program. If you have any answers, feel free to ask.
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Ron_Emad2 » Wed Apr 23, 2008 8:47 am

oh it is good
but i cant understand it
please build a poject with this code

:roll:
Hello
I from iran
i cant speak english correctly
please forgive me
User avatar
Ron_Emad2
Active Member
 
Posts: 85
Joined: Fri Oct 13, 2006 12:08 pm
Location: Iran-Kashan

Postby Lyberodoggy » Wed Apr 23, 2008 10:39 am

You can find the program I 've made using this here
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Ron_Emad2 » Wed Apr 23, 2008 12:07 pm

Thanks
I will go to this topic
i hope find it
with thanks
emad
Hello
I from iran
i cant speak english correctly
please forgive me
User avatar
Ron_Emad2
Active Member
 
Posts: 85
Joined: Fri Oct 13, 2006 12:08 pm
Location: Iran-Kashan


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron