Basically just a string encrypting. I'll post the decrypting program in a bit, when I get some time. The encrypting and decrypting are each kinda slow, so I was just wondering if anyone could help me with it. I'm looking for speed optimization; space optimization isn't that important right now. Here goes:
PRGM θENCR
Input "", Str1
Randint(1,64
sub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789",ans,1 ->Str0
For(θ,1,length(Str1
sub(Str1, θ,1 ->Str2
Delvar Y
For( Z, 1, 64
If sub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789",Z,1)=str2:Z -> Y
If Y≠0:64 ->Z
End
Y+A->Y
str0 + sub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789",Y,1 -> Str0
End
|
We're glad you came by, but you might find what you're looking for elsewhere. TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it. Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope. |
Please forgive any typos in the above post or in this one; I can't edit posts as a guess ;-;
All "ABCD…..6789" is just a shortened "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789".
PRGM θDECR
sub(Str0,1,1 -> Str9
". -> Str1
Delvar θ
While Str1 ≠ Str0
θ+1 -> θ
sub("ABCD…..6789",θ,1 -> Str1
End
Delvar Str1
θ -> R
Delvar L1
Setupeditor L1
For(θ,2,Length(Str1
Delvar W
For(Z,1,64
If sub("ABCD…..6789",Z,1)=Str1:Z ->W
If W≠0:64 -> Z
End
W -> L1(θ-1
End
L1-R -> L1
For(θ,1,dim(L1
If L1(θ )<1:64+L1(θ) -> L1(θ //Fixes negative values
End
": -> Str1
For(θ,1,dim(L1
Str1 + sub("ABCD…..6789",L1(θ ),1 -> Str1
End
PRGM θDECR (Optimized for speed)
sub(Str0,1,1 -> Str9
instring("ABCD…..6789",Str9 -> R
Delvar L1
Setupeditor L1
For(θ,2,Length(Str1
Delvar W
Instring("ABCD…..6789",Str1->L1
End
L1-R -> L1
For(θ,1,dim(L1
If L1(θ )<1:64+L1(θ) -> L1(θ //Fixes negative values
End
": -> Str1
For(θ,1,dim(L1
Str1 + sub("ABCD…..6789",L1(θ ),1 -> Str1
End
This code is an optimization of your code in both size and speed :)
PRGM θENCR
:Input "", Str1
:sub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789",RandInt(1,64),1 -> Str0
:For(θ,1,length(Str1
:inString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789",sub(Str1,θ,1 -> Y
:Y+A->Y
:Str0+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz .0123456789",Y,1 -> Str0
:EndAll I did was replace your method of converting the character into a number with the inString command.
What was:
Y+A->Y
for?
BTW this is for your first program. I'll look at your 2nd program later.
At some point in the near future (probably during calculus), I'm going to rewrite the encryption so it'll be harder to crack (I.E. the encryption key won't be the first character), as well as add support for more characters/tokens.
Here's an idea:
Convert each character into a number with the string-to-list routine as a list. But as a twist, don't use ABCDEFGHIJKLMNOPQRSTUVWXYZ as the reference. Have the user input a string to use as a reference - and they can put them in any order they wish.
To decrypt the list back into a string that makes sense, the user enters in the string they used before and you use the list-to-string routine (with their inputted string, not ABCDEFGHIJKLMNOPQRSTUVWXYZ, of course)!
What do you think?
Hmm, could work. The only problem I can think of would be them not putting in the exact same string and getting an error (I generally try to leave my code with as few possibilites for errors as possible) or i could write a routine that sorts their string so that as long as they have all the same characters in their string, it will work.
It's worth a shot,; I'll see what I can do.
I could also ask the user for a number to use in the offset, which makes it a 64-character encryption routine, and the key isn't stored in the string.
you might want to also hide the reference string by applying the reference string to the ABCDEFGHIJKLMNOPQRSTUVWXYZ method and hiding the outcome in another list. the hacker won't know which list is the reference or message and applying either one to the ABCD… method will be result in an confusing outcome because the reference will be a mix of characters.
The Silver Phantom welcomes you
Or just delete the reference string and have the user input it again as a password!
a two in one protection system…
a LOOOOONG password
a encryption code…
good idea…
but having the reference code be the password, if someone messes one letter for another, then thats 2 letters in the message they can easily change mentally to fit. i think keeping reference string in a list is better because the program can compare the given reference code to the original and prevents the translation
The Silver Phantom welcomes you
I see what you mean, but I don't like the idea of keeping the password inside the list…
Perhaps someone can produce an algorithm that creates a reference string from a single number? And vice versa?
Then the reference string could become a number to memorize and, if the algorithm is good, it'll be very hard to decipher the correlation between the number and a reference string.
I'll start thinking of something during the weekend…
good idea,
may be several algorithms so that 2 reference strings don't get one number, and it will assure that they have to be in the correct algorithm. so pretty much 3 or 4 numbers in a certain order that will all get the same reference code.
i'll try to work on such a translation.
The Silver Phantom welcomes you
Sounds good; I'm thinking along the lines of storing the initial number into rand and doing rand(number of characters in ref string) and using the card shuffling method (http:/ /tibasicdev.wikidot. com/randintnorep) to scramble the string.
God, I wish I could log in at school; it would make my life easier and it would let me have karma; I'm going to try copying the wikidot cookies from my other computer. I just have to hope that I can find the place to put it in a mac's filesystem.
For Boba.Foxx:
Whatever page is blocked for you, use https://grapesnake.com (its an http proxy) to get around the block. Your browser will probably tell the site's security has problems, and that it does not recomend using the site, but just ignore the warnings. Also, this method is probably against your school's "accaptable use policy" or something along those lines, so be ware.
Something like this?
Delvar A
Repeat A>0 and A<65
Input "Seed? ", A
End
A -> rand
rand(64 -> L1
seq(X,X,1,64 -> L2
SortA(L1,L2
": -> Str7
For(Z,1,64
Str7 + sub("ABCD….6789",L2(Z),1 -> Str7
End
If you want, add a
sub(str7,2,1 -> str0
seq(str0 + sub(str7,Z,1), Z, 2,64
to truncate the ":" out of str7
scratch that last line of code, it should be
for(Z,2,64
str0+sub(str7,Z,1) -> Str0
End
Sidenote: With this, you would use Str7 instead of the ABCD….6789, and you would either reference this code through another program at the beginning of each program or just copy it in over the key generation.
So far, I've worked out all the kinks (that I can find); I'm planning on writing a check into the encryptor and decryptor to ensure that all the characters are valid.
Other than that, I've added some nice text telling you what it's doing so that whenever it changes steps, they'll know that it is still doing stuff.
The best way to ensure all characters are valid: (to the best of my knowledge)
:If length(Str7)>max(L₁ // where the reference string is in Str7 and the encrypted info is in L₁
:Then
:ClrHome
:Disp "Invalid reference code!"
:Stop
:Enddont forget about repeats of the same character
The Silver Phantom welcomes you
No - repeats of the same character would be technically pointless and space-wasting, but it wouldn't cause an error with sub().
oh, i forgot that there was a starting point
The Silver Phantom welcomes you
by the way, what is the set of characters we're dealing with?
i have mirageOS data on my calc so i can do lowercase letters.
The Silver Phantom welcomes you
Wouldn't that just check the message length and not the character values?
It checks the length of the reference string, not the message length.
Oh, I see what it does now. Yeah, something like that would probably work; great idea! I'll probably add that in on Monday.
I was think along the lines of getting a string of all not supported characters and just using an instring after they input their string (as well as possibly outputting the invalid character).
I have a few more ideas; however they haven't taken a very definite form yet so I'll research them this weekend or later.
Xeda's made a really cool program called Xtra2 for that! There are 246 ASCII characters available on-calc. (I don't know why it's 246 and not 256…)
The program has other uses, most importantly Xtra variables, but for your purposes, it can do exactly what is needed:
Store all the special symbols to a string.
So, in thinking of algorithms:
1: Use Xtra to make a string of all ASCII characters
2: Ask for a number password; store to rand
2: Scramble the string using rand
3: Use string-to-list routine
4: Tell user to use same number password to decrypt
And to decrypt:
1: Use Xtra to make a string of all ASCII characters
2: Ask for the password; store to rand
2: Scramble the string using rand
3: Use list-to-string routine
4: Decrypted!
Sounds like it would work; only thing I can thing of would be how long it would take to scramble the string.
However, with there being no easy way to input more than half the ASCII characters, I don't really see much of a need for most of them being in the reference string.
You could also try to write a compression/decompression algorithm to add another level of complexity. For example, you could compress the data, then scramble it accordingly. Then, even if the user could descramble it, it would still be a mess. I came up with a pretty good algorithm (it usually achieved about 40% compression, but never more than 50%), but in BASIC, it would be reallly slow. My first implementation was with Celtic 3 doing most of the work and that took about 10 minutes to compress a 1000 byte string. In assembly it is a fraction of a second, though.
Z80 Assembly>English>TI-BASIC>Python>French>C>0
Or just have it store a ? into the encrypted string in its place; it's their fault for not following the guidelines.
(Note: I've updated both programs with progress percentages, as well as an 'allowed characters' guideline on the input screen (It says 'Allowed characters are A-Z, a-z, 0-9, , and .) so it shouldn't be a problem now)
I need to ask burr if he can attribute all these posts to my actual account that's never used.
Just remembered - there was a user that used to be on this forum named calccrypto and (s)he was involved in a lot of encryption discussions. I don't know where they went, but here's their wikidot page:
http://calccrypto.wikidot.com/
Check it out if you're interested!