Author Topic: Encoding and Decoding Text  (Read 3112 times)

0 Members and 1 Guest are viewing this topic.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Encoding and Decoding Text
« on: March 10, 2010, 08:52:54 pm »
Today I made a couple of routines to encode and decode text.  It stores the text into L1, 6 letters a list element.  You can have messages up to 128 characters long. :)

Code: [Select]
TEXTENCD

DelVar L1ClrHome
Input "",Str1
min(128,length(Str1->L1(1
23->dim(L1
DelVar C1->B
For(A,1,L1(1))
C+1-6(C=6->C
If C=1
B+1->B
L1(B)+10^(2C-2)inString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,.!?:'",sub(Str1,A,1->L1(B
End
B->dim(L1
L1


TEXTDECD

ClrHome
DelVar C1->B
For(A,1,L1(1
C+1-6(C=6->C
If C=1
Then
B+1->B
L1(Ans->D
End
.01int(D->D
int((A-1)/16
Output(1+Ans,A-16Ans,sub(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,.!?:'",1+100fPart(D),1
End

Comments? :D

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Encoding and Decoding Text
« Reply #1 on: March 10, 2010, 09:25:49 pm »
Nice routines! And great way to store huge amounts of text!
One of these days I'll get a sig I'm really proud of.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Encoding and Decoding Text
« Reply #2 on: March 10, 2010, 10:33:29 pm »
Very nice!  And i'm glad your excited about Portal :)

Although i can't figure out why you are limiting the string length to 128 O.o

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Encoding and Decoding Text
« Reply #3 on: March 11, 2010, 12:52:17 am »
Nice, altough I am unsure if I understand the concept well. Is it to compress text too or mostly to encrypt/decrypt? The screenshot doesn't show much.

Offline mapar007

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 550
  • Rating: +28/-5
  • The Great Mata Mata
    • View Profile
Re: Encoding and Decoding Text
« Reply #4 on: March 11, 2010, 10:35:54 am »
I think it, sort of, compresses data by taking advantage of the amount of data a REAL variable can contain. (the significand is 6 bytes, I think, which would explain the 6 letters/element ratio)

I'm sorry if this is completely wrong, but I didn't have the time to study your code.
« Last Edit: March 11, 2010, 10:37:47 am by mapar007 »

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: Encoding and Decoding Text
« Reply #5 on: March 11, 2010, 01:59:34 pm »
It's also useful when you don't want to save the string after the program, like the character's name that the user defined. Since string variable cannot be named like list, it would be very useful to convert the string to the list, and archive the list and delete the string.


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Encoding and Decoding Text
« Reply #6 on: March 11, 2010, 06:30:44 pm »
I think it, sort of, compresses data by taking advantage of the amount of data a REAL variable can contain. (the significand is 6 bytes, I think, which would explain the 6 letters/element ratio)

I'm sorry if this is completely wrong, but I didn't have the time to study your code.
This is completely right.  Though you could store 14 digits (7 two digit numbers), fpart( will not return the right value with that many digits.  :)

Although i can't figure out why you are limiting the string length to 128 O.o
I just limited it at 128 because there can only be 128 characters on the homescreen at once. :D

I'm glad you guys like it. ;D
« Last Edit: March 11, 2010, 06:31:16 pm by ztrumpet »