Page 2 of 3 <123>
Topic Options
#124268 - 2004-08-02 01:58 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, there was a problem.
shouldn't:
$=substr($p, (iif($d,$-$y,$y)+$r+o-1) mod $+1,1)

be:
$=substr($p, (iif($d,$-$y,$y)+$r+$o-1) mod $+1,1)
_________________________
!

download KiXnet

Top
#124269 - 2004-08-02 02:51 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it actually seems like there is another bug on that line too...
regarding the word-shift... didn't get my finger on it yet though.
_________________________
!

download KiXnet

Top
#124270 - 2004-08-02 02:58 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep, it's wrong.
Code:
   ;if decrypting:

; length of table minus keychar-index plus textchar-index plus word-shift minus one mod length of table.
; add one to that.
;if encrypting:
; keychar-index plus textchar-index plus word-shift minus one mod length of table. plus one.

_________________________
!

download KiXnet

Top
#124271 - 2004-08-02 03:05 PM Re: KiXgolf: Vigenere Cipher - Public coding
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
When i get a chance tonight, i will explain that last line (after i figure it out again).

But the reason the offset is added during decryption is basically because it's doing something like ($m -($-($o+1)) -> $m-($-$o-1) -> $m-$+$o+1


Edited by maciep (2004-08-02 03:09 PM)
_________________________
Eric

Top
#124272 - 2004-08-02 03:20 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, here is a fixed one.
checked from non-matching tests that jens' cipher is screwed up.
second test, not lcase chars:
K+K-first word = W not 5
I+I-first word = S not 1

so, this seemed to work correctly:
Code:
function vigenere($t,$k,optional $d)
dim $j,$r,$,$p,$o,$y
for $j = 65 to 90
$ = chr($j)+$+chr($j+32)
next
$p = "0123456789"+$
for $j = 1 to len($t)
do
$ = left($k,1)
$k = substr($k,2)+$
$y = instr($p,$)
until $y
$ = substr($t,$j,1)
$o = $o+($=" ") -$o*(0 $r = instr($p,$)
if $r
$ = 62 - (ucase($t+$k)=$t+$k)*26
$ = substr($p,1+($+$r+(2*($d=0)-1)*($y-$o-2)-1) mod $,1)
endif
$vigenere = $vigenere + $
next
endfunction




KiXtart
KiXtart Version = 4.22
KiXforms Version =
KiXGolf Script = kixgolf_vigenere.kix

Computer
OS = Windows 2000 Professional
CPU = Intel Pentium III Mobile
Speed = 933 MHz
Memory = 256 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Vigenere Cipher
Valid Cipher Ops = 7 (64%)
Processing Start = 2004/08/02 16:03:15.847
Processing End = 2004/08/02 16:03:19.973
Duration = 0000/00/00 00:00:04.125
KiXGolf Score = 367

Thank you for participating in KiXtart Golf!
press any key to close
_________________________
!

download KiXnet

Top
#124273 - 2004-08-02 03:21 PM Re: KiXgolf: Vigenere Cipher - Public coding
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Are we three the only ones that even gave this shot?




Sadly I was in Marbella last week. I tried to convince the missus that the golf was more important, but she couldn't see it

Top
#124274 - 2004-08-02 03:22 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, it might be right...
well, I anyway changed it to better understand :P

and "$o" being just "o" was definitely wrong.
_________________________
!

download KiXnet

Top
#124275 - 2004-08-02 08:06 PM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
569, no word shift:

Code:

Function Vigenere($a,$b, optional $c)
Dim $t,$u,$i,$j
$t='0123456789ZYXWVUTSRQPONMLKJIHGFEDCBA'
$u='abcdefghijklmnopqrstuvwxyz'

;remove wrong chars in key
For $i=1 to Len($b)
If InStr($t+$u,SubStr($b,$i,1))
$j=$j+SubStr($b,$i,1)
EndIf
Next

$b=$j

;check for lowercase in string/key, if so expand tableau
$j=Len($a)+Len($b)
For $i=1 to $j
If InStr($u,SubStr($a,$i,1)) OR InStr($u,SubStr($b,$i,1))
$t=$t+$u
$i=$j
EndIf
Next

;double the tableau
$t=$t+$t

;make the key larger than the string
While Len($b) < Len($a)
$b=$b+$b
Loop

For $i=1 to Len($a)
$j=SubStr($a,$i,1)
$u=SubStr($b,$i,1)
If InStr($t,$j)
If $c
$j=SubStr($t,InStrRev($t,$j)+Len($t)/2-InStrRev($t,$u)+1,1)
Else
$j=SubStr($t,InStr($t,$j)+InStr($t,$u)-1,1)
EndIf
EndIf
$vigenere=$vigenere+$j
Next

EndFunction

_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#124276 - 2004-08-02 10:27 PM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
WRONG WRONG WRONG - see later for explanations - current score is stil 367!!!

Code:

Function vigenere($t,$k,optional $d)
DIM $j,$r,$,$p,$o,$y
For $j=65 To 90
$=CHR($j)+$+CHR($j+32)
Next
$p = "0123456789"+$
For $j = 1 To Len($t)
Do
$ = Left($k,1)
$k = SubSTR($k,2)+$
; $y = InSTR($p,$)
; Until $y
Until InSTR($p,$)
$ = SubSTR($t,$j,1)
$o = $o+($=" ") -$o*(0<InSTR('!.?',$)) $r = InSTR($p,$)
If $r
$ = 62 - (UCase($t+$k)=$t+$k)*26
$ = SubSTR($p,1+($+$r+(2*($d=0)-1)*($y-$o-2)-1) mod $,1)
EndIf
$vigenere = $vigenere + $
Next
EndFunction



Gives:


KiXtart
KiXtart Version = 4.22
KiXforms Version =
KiXGolf Script = KIXGOL~1.KIX

Computer
OS = Windows XP Professional
CPU = Intel Pentium II
Speed = 448 MHz
Memory = 384 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Vigenere Cipher
Valid Cipher Ops = 10 (100%)
Processing Start = 2004/08/02 22:13:45.220
Processing End = 2004/08/02 22:13:45.481
Duration = 0000/00/00 00:00:00.260
KiXGolf Score = 362

Thank you for participating in KiXtart Golf!


Edited by MightyR1 (2004-08-02 10:40 PM)
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#124277 - 2004-08-02 10:33 PM Re: KiXgolf: Vigenere Cipher - Public coding
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Patrick, how can you do that? Something is not right.

You remove $y as a valid var...

; $y = InSTR($p,$)
; Until $y

then try to use it ...

$ = SubSTR($p,1+($+$r+(2*($d=0)-1)*($y-$o-2)-1) mod $,1)


do you have the latest download test code?


Edited by Howard Bullock (2004-08-02 10:34 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#124278 - 2004-08-02 10:37 PM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
duh.....

Does damn editors. I take te previous post back. For some reason, not the KiXGolf_vigenere.txt contained the results, but the KiXGolf_vigenere_rules.txt does????

Will investigate.
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#124279 - 2004-08-02 10:46 PM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
It's the shortname stuff.
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#124280 - 2004-08-02 10:49 PM Re: KiXgolf: Vigenere Cipher - Public coding
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Lonkero, your last posted function will not work correctly. It's due to the modular math. the reason i had mod $ + 1, is because if the character were say 62, then 62 mod 62 = 0 and your substr would then be "".

so i had the math built in to substract 1 from the char position, then do the modular math and then add 1. So it would be (62-1) mod 62 + 1 = 62. Makes sense?
_________________________
Eric

Top
#124281 - 2004-08-02 11:10 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that's why I have the -1 in there.
thus 1+((62-1) mod 62) = 62

and as far tests show, it works where your code failed.
hmm... your last line is actually just the same as my code does.
you can test it out and see it work.


Edited by Lonkero (2004-08-02 11:13 PM)
_________________________
!

download KiXnet

Top
#124282 - 2004-08-02 11:19 PM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Could anyone explain the $ = SubSTR($p,1+($+$r+(2*($d=0)-1)*($y-$o-2)-1) mod $,1)
line to me? I'm getting dizzy over it...


Edited by MightyR1 (2004-08-02 11:33 PM)
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#124283 - 2004-08-02 11:43 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, it's rather complicated.
something like:
if $d
$block=$lenOfTable+$locationOfTextsCharInTable-1*($locationOfKeywordCharInTable-$wordshift-2)
else
$block=$lenOfTable+$locationOfTextsCharInTable+($locationOfKeywordCharInTable-$wordshift-2)
endif
$placeInTable=1+(($block-1) mod $lenOfTable)
$char = SubSTR($tableau,$placeInTable,1)

_________________________
!

download KiXnet

Top
#124284 - 2004-08-03 12:02 AM Re: KiXgolf: Vigenere Cipher - Public coding
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Oh, didn't look on the left for it. My bad, Nevermind.
_________________________
Eric

Top
#124285 - 2004-08-03 12:19 AM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Complicated indeed!!

I'm gonna sleep over it.
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#124286 - 2004-08-04 02:48 PM Re: KiXgolf: Vigenere Cipher - Public coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what about this then?

function vigenere($t,$k,optional $d)
dim $j,$r,$,$p,$o,$y
for $j = 65 to 90
$ = chr($j)+$+chr($j+32)
next
$p = "0123456789"+$
for $j = 1 to len($t)
do
$ = left($k,1)
$k = right($k,-1)+$
$y = instr($p,$)
until $y
$ = substr($t,$j,1)
$o = $o+($=" ") -$o*($=!|$='?'|$='.')
$r = instr($p,$)
if $r
$ = 62 - (ucase($t+$k)=$t+$k)*26
$ = substr($p,1+($+$r+(2*($d=0)-1)*($y-$o-2)-1) mod $,1)
endif
$vigenere = $vigenere + $
next
endfunction




KiXtart
KiXtart Version = KiXtart 2001 4.22 Release Candidate 1
KiXforms Version =
KiXGolf Script = kixgolf_vigenere.kix

Computer
OS = Windows 2000 Professional
CPU = Intel Pentium II
Speed = 398 MHz
Memory = 384 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Vigenere Cipher
Valid Cipher Ops = 7 (64%)
Processing Start = 2004/08/04 15:31:23.896
Processing End = 2004/08/04 15:31:24.246
Duration = 0000/00/00 00:00:00.349
KiXGolf Score = 366

Thank you for participating in KiXtart Golf!
_________________________
!

download KiXnet

Top
#124287 - 2004-08-04 04:15 PM Re: KiXgolf: Vigenere Cipher - Public coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Shouldn't $=! be $='!'
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
Page 2 of 3 <123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.078 seconds in which 0.028 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org