Squares

General FreeBASIC programming questions.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Moderator

Postby albert » May 12, 2020 22:40

A little side program , to test for mod values..

It tells you ; what 3 mods , solve all 128 values , ( 0 to 127 )..

I thought ; maybe the mods i was using , weren't getting all 128 values correct...

Then i thought ; maybe it was due to , overlaps , one mod going over 10.. But it sometimes decompresses when there are overlaps of values.

I can't find the bug or error....

Here's my "Moderator" program...

Code: Select all


screen 19

dim as longint v , v1 , v2 , v3 , v4
dim as longint  md1 , md2 , md3 , md4
do
           
            do
                'ADJUST ( RND * ? ) TO DIFFERENT VALUES , HAS TO BE 3 OR GREATER
                'YOU CAN PLAY AROUND AND FIND THE LOWEST MODS THAT EQUAL ( V ) BELOW.
                md1 = int( rnd * 3 )
                md2 = int( rnd * 8 )
                md3 = int( rnd * 16 )
               
            loop until md1 > 1 and md2 > 1 and md3 > 1
           
            'SET ( V ) TO MAX BIT VALUE YOU WANT TO SEARCH.
            dim as longint count = 0
            for v as longint = 0 to  127
               
                v1 = v mod md1
                v2 = v mod md2
                v3 = v mod md3
               
                dim as longint s , s1 , s2 , s3 , s4 , value
                'IF YOUR DOING MORE THAN 16 BITS SET ,BELOW TO MAX BIT VALUE
                for b as longint = 0 to 127 step 1
                    s = b
                    s1 = s mod md1
                    s2 = s mod md2
                    s3 = s mod md3
                    if s1 = v1 and s2 = v2 and s3 = v3 then value = b : exit for
                next
               
                if value = v then count+=1
               
            next
               
            if count = 128 then print count , md1 , md2 , md3 : sleep
           
        'if v = value then print v , value  , md1 , md2 , md3 : sleep
       
loop until inkey = chr( 27 )

sleep
end

albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Moderator

Postby albert » May 12, 2020 23:07

I found the error..... It happens when you create a string out of the values..

So i modified the "Moderator" to do strings...

Here's the "Moderator" program again..

Code: Select all


screen 19

dim as longint v , v1 , v2 , v3 , v4
dim as longint  md1 , md2 , md3 , md4
do
           
            do
                'ADJUST ( RND * ? ) TO DIFFERENT VALUES , HAS TO BE 3 OR GREATER
                'YOU CAN PLAY AROUND AND FIND THE LOWEST MODS THAT EQUAL ( V ) BELOW.
                md1 = int( rnd * 3 )
                md2 = int( rnd * 20 )
                md3 = int( rnd * 32 )
            '   
            loop until md1 > 1 and md2 > 1 and md3 > 1
           
            'SET ( V ) TO MAX BIT VALUE YOU WANT TO SEARCH.
            dim as longint count = 0
            for v as longint = 0 to  127
               
                v1 = v mod md1
                v2 = v mod md2
                v3 = v mod md3
               
                dim as string out1 = right( "000" + str( ( v1 * 100 ) + ( v2 * 10 ) + v3 ) , 3 )
               
                dim as longint s , s1 , s2 , s3 , s4 , value
                'IF YOUR DOING MORE THAN 16 BITS SET ,BELOW TO MAX BIT VALUE
                for b as longint = 0 to 127 step 1
                   
                    s = b
                    s1 = s mod md1
                    s2 = s mod md2
                    s3 = s mod md3
                   
                    dim as string out2 = right( "000" + str( ( s1 * 100 ) + ( s2 * 10 ) + s3 ) , 3 )
                   
                    if out2 = out1 then value = b : exit for
                   
                    'if s1 = v1 and s2 = v2 and s3 = v3 then value = b : exit for
                   
                next
               
                if value = v then count+=1
               
            next
               
            if count = 128 then
                color 14
                print "total correct = " ; count , md1 , md2 , md3 : sleep
            else
                color 8
                print "total correct = " ; count , md1 , md2 , md3 : sleep
            end if
             
        'if v = value then print v , value  , md1 , md2 , md3 : sleep
       
loop until inkey = chr( 27 )

sleep
end

angros47
Posts: 1673
Joined: Jun 21, 2005 19:04

Re: Squares

Postby angros47 » May 12, 2020 23:21

Albert, do you know that "MOD" stands for "modulus", not for "moderator", right?
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » May 12, 2020 23:38

@angros47

"Moderator" is a play on "Terminator" The Arnold Schwarzenegger movies...

The MOD program is terminus , Finito.

Just run the program , and hold a key down , and look for the highlight answers , they are the only ones that get all 128 values correct.

I ran it for a while , and it seems that , 2 , 8 , 17 seems to be the lowest values.. Which would amount to a 0 to 186... and 86 is finito
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » May 13, 2020 0:18

2 , 8 , 17 doesn't compress..It expands 100,000 bytes to 200,000 bytes after 100 loops.. -98%
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Moderator

Postby albert » May 13, 2020 1:15

I modified the "Moderator"
So now you don't have to hold the key down..

It progresses on it's own.. and stops when it hits on 3 values that solve all 128 values ( 0 to 127 )..

Code: Select all


screen 19

dim as longint v , v1 , v2 , v3 , v4
dim as longint  md1 , md2 , md3 , md4
do
           
            do
                'ADJUST ( RND * ? ) TO DIFFERENT VALUES , HAS TO BE 3 OR GREATER
                'YOU CAN PLAY AROUND AND FIND THE LOWEST MODS THAT EQUAL ( V ) BELOW.
                md1 = int( rnd * 4 )
                md2 = int( rnd * 5 )
                md3 = int( rnd * 78 )
            '   
            loop until md1 > 1 and md2 > 1 and md3 > 1
           
            'SET ( V ) TO MAX BIT VALUE YOU WANT TO SEARCH.
            dim as longint count = 0
            for v as longint = 0 to  127
               
                v1 = v mod md1
                v2 = v mod md2
                v3 = v mod md3
               
                dim as string out1 = chr( val( right( "000" + str( ( v1 * 100 ) + ( v2 * 10 ) + v3 ) , 3 ) ) )
               
                dim as longint s , s1 , s2 , s3 , s4 , value
                'IF YOUR DOING MORE THAN 16 BITS SET ,BELOW TO MAX BIT VALUE
                for b as longint = 0 to 127 step 1
                   
                    s = b
                    s1 = s mod md1
                    s2 = s mod md2
                    s3 = s mod md3
                   
                    dim as string out2 = chr( val( right( "000" + str( ( s1 * 100 ) + ( s2 * 10 ) + s3 ) , 3 ) ) )
                   
                    if out2 = out1 then value = b : exit for
                   
                    'if s1 = v1 and s2 = v2 and s3 = v3 then value = b : exit for
                   
                next
               
                if value = v then count+=1
               
            next
               
            if count = 128 then
                color 14
                print "total correct = " ; count , md1 , md2 , md3 : sleep
            else
                color 8
                print "total correct = " ; count , md1 , md2 , md3
            end if
             
        'if v = value then print v , value  , md1 , md2 , md3 : sleep
       
loop until inkey = chr( 27 )

sleep
end



( !!~~EDITED~~!! )
angros47
Posts: 1673
Joined: Jun 21, 2005 19:04

Re: Squares

Postby angros47 » May 13, 2020 23:07

Albert, you promised to stop posting your compressing code until you had a working decompressor: https://freebasic.net/forum/viewtopic.php?p=271960#p271960

So, please, keep your word.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » May 14, 2020 2:31

I thought up another encryption idea..

You take a book , and chapter... any book and chapter.

Then you take the message and count the letters of the chapter , till it hits on the next letter of the message..
Then you start at zero and count till the next letter of the message.

If the letter is over a certain value , then you can do negatives to hit the letter.. ( you back up a number of letters. )

It would just look like a string of numbers... without knowing the book and chapter to compare it to.
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » May 14, 2020 4:12

@Albert
You should not be wasting your time inventing simple ciphers until you have broken a few real world ciphers and can understand how trivial it is to reverse the process using statistics and a dictionary.
angros47
Posts: 1673
Joined: Jun 21, 2005 19:04

Re: Squares

Postby angros47 » May 14, 2020 20:12

Perfect encryption is nothing new

https://en.wikipedia.org/wiki/One-time_pad

Basically, even with the simplest encrypting algorithm, if the encryption key is as long as the message, it's impossible to decrypt it (a brute force approach will be useless if there is no way to check the correctness of the decrypted message, and odds to guess the right key are the same of guessing the message itself)
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » May 15, 2020 23:40

@angros47

There is no key. to the encryption.. just numbers equating to letters..


Sentence = "This is an encrypted sentence , I'm working on..

Message = "see me"

Output = 22 , 1 , 0 , 11 , -6 ( the 0 could be a 3 )
Output = s e e , m , e

I may have miscounted on some of the letters...

If there's another "s" or "m" , then they would have different numbers.. so you couldn't say all 22's are "S"
The message keeps progressing through the chapter...

I guess you could say , the book and chapter is the "Key" , You could use the bible book "Numbers" chapter 3
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » May 16, 2020 0:52

Albert wrote:I may have miscounted on some of the letters...
This is a problem. If you make one mistake the whole message falls apart from that point.
The enemy cryptanalysts will be correcting and reading your messages long before your cipher clerk has delivered the message to the intended recipient.

Your cipher is so trivial that it would never be used seriously. 100 years ago there were a few groups using ciphers like that. Their messages were solved and used as evidence in their trials. The rebels and spies were shot, the smugglers were imprisoned.

Your ciphers are the kiss of death for their users.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » May 16, 2020 1:14

@Richard

You got to make the cypher output , so that it doesn't look like a cypher output...

You use numbers 00 to 99

Then you embed the computer with a bunch of like numbers.. That go with a math program.. Like Big-Calc..
So the output looks like a "Big-Calc" output..

If the cypher starts with a "9" then you know its a cypher , else its random data..
So you can send all the numbers over the internet , and the recipient knows which number is the cypher..

You could take the square root of the cypher , and embed that into the bunch of numbers.. or divide by 3333 (4 butt's )


Me , myself ; never use encryption.. The only people that use encryption are governments and criminals ( mafioso's ).
There are some companies , using encryption for cell phones and web browsing..
Me , myself ; I don't have any secrets to keep or convey..
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » May 16, 2020 2:20

@Albert. If you don't need a cipher, then why do you waste time posting silly, error prone ciphers that no one would ever use?
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » May 16, 2020 2:39

@Richard

I was working on compression , and realized that , ( if it doesn't compress ) and can be decompressed then it's encryption..
That lead me to work and think on all kinds of cipher ideas...

In the United States , there's a law that all encryption programs , have to come with source code..
So i started thinking ; how to cypher data , when you have to distribute it with the source code..
The source code would give up the algorithm..
So i thought up Vari_Cyph.. It comes with the source code and there's nothing in the source code , to give up the ciphered output.
You can comb through the source code , and there's nothing there to hint to the output..

Return to “General”

Who is online

Users browsing this forum: No registered users and 5 guests