Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2008-01-29 05:43:38

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

One-way function; VB

For x = 0 To 1
    CompiledString = CompiledString & Password(x).Text
Next

CompiledString = CompiledString & UserName.Text

For x = 1 To Len(CompiledString)
    Output = Output & Int(Asc(Mid(CompiledString, x, 1)) + Asc(Mid(CompiledString, Int(((x + Sqr(Len(Output))) Mod (Len(CompiledString) - 1)) + 1), 1)))
Next

I will give high praise to anyone who thinks they know how to retrieve the original information and actually can.

For those without VB 5.0 compilers, here are the results:

UserName.text = afoiadfjanwief
Password(0).Text = wedraixdn
Password(1).Text = rhescaiufenxe
Output = 21320613321521521313720022519321622014020622920020522023114221614781235202229213137230211142153220216199211202222221210230215201203226196197207223199211229225203216203211219194205222206211214220220200199224218202224217206217202221219201201217196207224222203212212152217201203210216206212207214198224203209206134
UserName.text = aerjxosadmxxicwwmdxMALW
Password(0).Text = adxneuXddwriox
Password(1).Text = XAwjixnckefexnIXern
Output = 21320613321521521313720022519321622014020622920020522023114221614781235202229213137230211142153220216199211202222221210230215201203226196197207223199211229225203216203211219194205222206211214220220200199224218202224217206217202221219201201217196207224222203203207220221207203199205185165221212202230229204208204198220230183189218202210185166233226216235207199216221222206219229192197221191175173188211206240221216214188209185239211204239229208207221179166196197170201234220198218202206208176234203205229230219206220221210220230150153177201207197221224207208211203162219215225240215198226220211201240187153177201207197221224207237199215185165228226225225229218216201222178185186160185201234220198218202206185230221202220219219227206201220239219173208178179186188211206240221216214188209208185224205224239219199227178178188217210193198202231198197201233220225222235185165228225240215198226220211201240187138164188211210217211215223208215197219223225231225187184238215205240187164183188199201240220190176201214229211206225226208176234203205229230219212200221220219173208178179186184198214226230212232185200209239234210210239207165239183170196221201139217206202152209184197213219218198215198210225143220212132225221235221131229230141149239178165190184

What gave

Output = 1811291842231331601942231331901811982221911291831291921982151981692092151401201292322052191872062231402101551412332202062296421515764156213212213233232205215133212139147172125199213206224148181218228215199218147227172207225216185205140184149211230198235116171219211142191208211

Last edited by Laterally Speaking (2008-01-29 05:57:48)


"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#2 2008-01-29 06:57:43

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: One-way function; VB

my god VB is more horrible a language than i ever believed, how can you bear working with it? tongue

if you could explain what the & operator does for strings and what Asc and Mid do i might be able to have a try ;p im guessing Sqr squares the number.

Last edited by luca-deltodesco (2008-01-29 06:58:14)


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#3 2008-01-29 07:50:32

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

Re: One-way function; VB

string & string -> puts the two strings together, in the order they are typed, to form one longer string
Asc(string) -> gives the ASCII value of the first character in the string
Mid(string, integer, [integer]) -> returns the section of the string starting at the position defined by the first integer, and of length defined by the second integer (if it is not present, it returns the text from the starting point to the end of the string)
sqr(integer) -> returns the square root of the number

VB does have a few nice things about it: It isn't case-sensitive, you can leave out spaces, etc., and it corrects it without prompting; furthermore, there are no compilers for Java that have as much freedom for the user interface. There are also many different ways of achieving the same result, from simple to complex, long to short.

I have to agree, however, that there could be some improvements.

Last edited by Laterally Speaking (2008-01-29 08:21:42)


"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#4 2008-01-29 08:15:08

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,534

Re: One-way function; VB

The "string concatenation operator" is one of my main sources of bugs:

PHP: string . string
VB: string & string
actionscript/javascript: string + string (but if the string look like numbers they get added!)

And VB.net is not barbaric ... it is basically just another way of writing the same thing as you would in any other .net language, is fully object oriented, and has the same access to all.net functions, etc, and gets compiled into the same "Intermediate Language".

But when working in VB.net I keep adding ";" to the end of every line and using { } instead of "then end if"


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#5 2008-01-29 08:24:36

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

Re: One-way function; VB

In VB, if the strings are numbers, the string + string adds the numbers, but, if they aren't numbers, it "concatenates" them.
Thus, for strings, in VB, the + and & operators do the same thing.

Note that I am not using VB.net, but VB 5.0. There is a world of difference between the two. VB.net is similar to Java. Standard VB is an older language, much less strict as far as syntax goes.

Last edited by Laterally Speaking (2008-01-29 08:27:45)


"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#6 2008-01-29 12:22:11

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,534

Re: One-way function; VB

VB.net is much better than VB. Instead of buying it, you might like to try "SharpDevelop": http://www.icsharpcode.net/OpenSource/SD/ andlet us know if it is any good.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#7 2008-01-29 23:49:10

NullRoot
Member
Registered: 2007-11-19
Posts: 162

Re: One-way function; VB

I personally like VB, but I mainly use VBA with Excel. I'll have a go at this later. I think it's doable from a glance, but I'll need to play with it.


Trillian: Five to one against and falling. Four to one against and falling… Three to one, two, one. Probability factor of one to one. We have normality. I repeat, we have normality. Anything you still can’t cope with is therefore your own problem.

Offline

#8 2008-01-29 23:58:02

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

Re: One-way function; VB

Unless I made some huge mistake, which is possible, the only way to get back to the original string is the good ol' brute-force method.


"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#9 2008-01-30 00:40:32

NullRoot
Member
Registered: 2007-11-19
Posts: 162

Re: One-way function; VB

No, it's fine the way you've done it.
A major step in deciphering it would be to know the total length of the three strings. Even if you were able to deduce that somehow
you'd still be unable to determine what part of the concatenated string is Password0, Password1, and UserName. I thought there was
a clue in the encoding string, but that was before I realised all three strings went into the same variable.


Trillian: Five to one against and falling. Four to one against and falling… Three to one, two, one. Probability factor of one to one. We have normality. I repeat, we have normality. Anything you still can’t cope with is therefore your own problem.

Offline

#10 2008-01-30 02:30:53

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

Re: One-way function; VB

All right; I'll simplify the challenge: could you simply deduce the concatenated string from the end result?


"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#11 2008-01-30 04:13:42

NullRoot
Member
Registered: 2007-11-19
Posts: 162

Re: One-way function; VB

Can you double check the output you gave? I'm assuming that the words are alpha only with upper and lower case. Examples I've tried
so far seem to all produce a 3 digit number for each letter either beginning with 1 or 2. The length of the output you've given isn't
divisible by three. smile
If I'm right, then I believe there is a method, but it does involve brute force (of a kind). It appears initially that for any given string length
each letter corresponds to a specific number depending upon it's position regardless of the other letters around it. I'd basically have to
calculate a massive lookup table.
Assuming I can deduce the length of the string by len(string)/3, then I can use the lookup table to deduce the values for each 3-digit number.

This is all dependant on the fact that the number you gave is missing a digit or two, though wink


Trillian: Five to one against and falling. Four to one against and falling… Three to one, two, one. Probability factor of one to one. We have normality. I repeat, we have normality. Anything you still can’t cope with is therefore your own problem.

Offline

#12 2008-01-30 05:14:58

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

Re: One-way function; VB

The entered strings can contain any ASCII characters, as well as numbers. It seems that I did forget the following:

Dim CompiledString As String
Dim Output As String
Dim x As Integer

"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#13 2008-01-30 05:29:47

NullRoot
Member
Registered: 2007-11-19
Posts: 162

Re: One-way function; VB

Curses! Well that certainly makes it much harder to discern the length of the original string. It might still be doable, but it would require
that when a number is encoded, the result never starts with a 1 or 2. That way you could check if the number begins 1 or 2, if so, isolate the
3 digit code, if not, then isolate the 2 digit code.

I think that if all ASCII characters are potentially allowed (specifically things like .,?!$* etc) that will probably kill off any ability to decode it.


Trillian: Five to one against and falling. Four to one against and falling… Three to one, two, one. Probability factor of one to one. We have normality. I repeat, we have normality. Anything you still can’t cope with is therefore your own problem.

Offline

#14 2008-01-30 05:40:54

Laterally Speaking
Real Member
Registered: 2007-05-21
Posts: 356

Re: One-way function; VB

Nah. You can always brute-force it, but it takes a lot longer.

Here is what makes it impossible to do by any other means than brute-force:
The result is the concatenation of the previous result and the sum of the ASCII values of two characters in the string, the first one cycling through the entire length of said string, the other's position defined by the square root of the length of the previous result.


"Knowledge is directly proportional to the amount of equipment ruined."
"This woman painted a picture of me; she was clearly a psychopath"

Offline

#15 2008-01-30 21:31:05

NullRoot
Member
Registered: 2007-11-19
Posts: 162

Re: One-way function; VB

I meant an 'intelligent' method but you're quite right, anyway. I was reading the ASC(...MOD...) one incorrectly.
When I sat down and experimented I saw that I misinterpreted. Bummer smile.


Trillian: Five to one against and falling. Four to one against and falling… Three to one, two, one. Probability factor of one to one. We have normality. I repeat, we have normality. Anything you still can’t cope with is therefore your own problem.

Offline

Board footer

Powered by FluxBB