• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

caelum
8-Feb-2013
[1651]
Replacing pop with apop, spop or pops in mailbox all produce the 
same error:
    ** Access Error: Invalid port spec: scheme apop
GrahamC
9-Feb-2013
[1652]
See here http://stackoverflow.com/questions/1128826/downloading-mail-from-hotmail
caelum
23-Feb-2013
[1653]
So I have a question about RSA encryption. When I run the following 
code:

  rsa-key: rsa-make-key
  rsa-generate-key rsa-key 1024 3

  crypt-key: copy/part checksum/secure mold now/precise 16
  print crypt-key

  crypt-key: rsa-encrypt rsa-key crypt-key
  print crypt-key

  crypt-key: rsa-encrypt/private/decrypt rsa-key crypt-key
  print crypt-key


it runs perfectly, encrypts the crypt-key and then decrypts it sucessfully.


As you probably know, the purpose of the RSA algorithm is to allow 
someone else to encrypt data that only you can decrypt using your 
private key. I tried this with a different public key using the following 
code:

  rsa-key1: rsa-make-key
  rsa-generate-key rsa-key1 1024 3

  rsa-key2: rsa-make-key
  rsa-key2/n: rsa-key1/n

  crypt-key: copy/part checksum/secure mold now/precise 16
  print crypt-key

  crypt-key: rsa-encrypt rsa-key2 crypt-key
  print crypt-key

  crypt-key: rsa-encrypt/private/decrypt rsa-key2 crypt-key
  print crypt-key


So I put the public key from rsa-key1 into another object, rsa-key2 
and tried using it to encrypt the data and get the following error.

	#{DD44AC1810E9A7020FAD72A7CFA54100}
	Segmentation fault


How do I get the public key from the first object into the second 
object so that it can be used to encrypt data?
Cyphre
23-Feb-2013
[1654x4]
caelum, I corrected your non-working exaple:
;key1 - contains public and private keys
rsa-key1: rsa-make-key
rsa-generate-key rsa-key1 1024 3

;key2 - contains only public key
rsa-key2: rsa-make-key
rsa-key2/e: 3
rsa-key2/n: rsa-key1/n

;data to ecrypt encrypt 
data: copy/part checksum/secure mold now/precise 16

;encrypt data using the key2 (with pub key only)
crypt-key: rsa-encrypt rsa-key2 data


;decrypt data(that have been encrypted using key2) using the key1(needs 
to contain private key)
data2: rsa-encrypt/private/decrypt rsa-key1 crypt-key

either equal? data data2 [
	print "decrypted data match the original - decription passed"
][

 print "decrypted data differs from the original - decryption failed"
]
the problem was you forgot to set the generator value (key/e) when 
makeing rsa-key2
and also you tried to decrypt the data using rsa-key2 which doesn't 
contain the private key
caelum
23-Feb-2013
[1658]
Got it! Thanks Cyphre, much appreciated.
caelum
27-Feb-2013
[1659]
Another question. On linux (linux mint debian) these segments of 
code are part of a larger program. I separated them out because they 
are causing trouble when I try to 'enface' them.


    set-net [[me-:-mydomain-:-net] mail.mydomain.net pop.mydomain.net none 
    none none "[me-:-mydomain-:-net]" "PASSWORD"]


    open [scheme: 'pop user: "[me-:-mydomain-:-net]" pass: "PASSWORD" host: 
    "mail.mydomain.net"]


The code encapsulates without errors, but when I run the program 
after 'enface' it gives the following errors:

    Set-Net not provided.

    ** Access Error: Invalid port spec: scheme pop user [me-:-mydomain-:-net] 
    pass PASSWORD host mail.mydomain.net

    ** Near: open [scheme: 'pop user: "[me-:-mydomain-:-net]" pass: "PASSWORD" 
    host: "mail.mydomain.net"]


I would like to be able to 'enface' these code snippets. Any suggestions 
as to how to fix this would be most welcome?
GrahamC
27-Feb-2013
[1660]
if set-net is not defined, get the source and add it to your script
caelum
27-Feb-2013
[1661x2]
set-net is in the source exactly as above, 'enface' is refusing to 
compile it, but it compiles (almost) the rest of the program just 
fine.
I was wrong. Simple programs like (print "Hello World") compile and 
execute, but programs with a lot of code compile but produce a series 
of errors when executed. I noticed a pattern. Wherever a word is 
not followed by ':' causes errors, examples below. Perhaps it's just 
this linux version of enface?

    stylize [
        fld80: field 80x28 font-size 17 white ivory center
        .......
    ]

produces the error:

    ** Script Error: stylize has no value
    ** Near: new-styles: stylize [
        fld80: field 80x28 font-size 17 white ivory center 
        fld400: field 400x28 font-size 17 whit...

I'll try this on windows when I have the opportunity.
GrahamC
27-Feb-2013
[1663x2]
You haven't included view.r
without this no view or vid stuff will run after being encapped
caelum
27-Feb-2013
[1665]
Thanks GrahamC. Where do I find view.r? I just searched my whole 
HD for it. Not there.
GrahamC
27-Feb-2013
[1666x3]
it should be in the <sdk>/source directory
this is mine
#include %gfx-colors.r
#include %gfx-funcs.r

#include %view-funcs.r
#include %view-vid.r
#include %view-edit.r
#include %view-feel.r
#include %view-images.r
#include %view-styles.r
#include %view-request.r


;-- Must be done prior to loading anything that requires fonts on 
Linux.

layout [text "imanXwin kludge"] ;-throw this one away soon-- okay?

open-events
caelum
27-Feb-2013
[1669]
I just copied all the SDK stuff back onto my main HD and I found 
view.r. Thanks for that GrahamC. I'll retry encapping my program 
with the includes..
caelum
28-Feb-2013
[1670]
I have included view.r and now have the graphical elements working 
after 'enface', thanks GrahamC. But I'm still getting the other errors: 
This is all to do with setting up the email parameters:

    Set-Net not provided.

    ** Access Error: Invalid port spec: scheme pop user [me-:-mydomain-:-net] 
    pass PASSWORD host mail.mydomain.net

    ** Near: open [scheme: 'pop user: "[me-:-mydomain-:-net]" pass: "PASSWORD" 
    host: "mail.mydomain.net"]
GrahamC
28-Feb-2013
[1671]
If you did a grep on your source directory you'll find it ... in 
prot-setnet.r
caelum
28-Feb-2013
[1672]
I found set-net in prot-setnet.r and included it with the same includes 
of GrahamC above, and now I get this error:

** Script Error: Invalid path value: pop
** Where: forskip
** Near: forall settings [
    if (item: first settings) = 'none [item: none] 
    if word? item [item: form item] 
    do first ...


Not sure where to go from here as I don't know what I am looking 
at in terms of errors.
GrahamC
28-Feb-2013
[1673]
show us your include files
caelum
28-Feb-2013
[1674]
Same as yours only with prot-setnet.r added.

#include %gfx-colors.r
#include %gfx-funcs.r

#include %view-funcs.r
#include %view-vid.r
#include %view-edit.r
#include %view-feel.r
#include %view-images.r
#include %view-styles.r
#include %view-request.r

#include %prot-setnet.r


;-- Must be done prior to loading anything that requires fonts on 
Linux.

layout [text "imanXwin kludge"] ;-throw this one away soon-- okay?

open-events
GrahamC
28-Feb-2013
[1675x3]
you don't have any protocols
you need to include prot.r
and then remove prot-setnet.r or just add the protocols you need
caelum
28-Feb-2013
[1678]
Got it! Now I see how it all works and I have 'enface' working on 
linux. Many Thanks for your help!
NickA
10-Mar-2013
[1679]
What's the proper (fast) way to do this?

    REBOL [title: "Anagram List"]
    a: copy []
    mix: func [str prev] [   
        repeat i length? str [
            picked: pick str i
            rest: head remove at copy str i
            append a rejoin [prev picked rest]
            mix rest join prev picked
        ]
    ]
    mix input: ask "Text:  " ""
    editor unique a
Sunanda
11-Mar-2013
[1680]
Don't know if it is faster or more proper, but it's another way:
   http://www.rebol.org/view-script.r?script=lexpem.r
Steeve
11-Mar-2013
[1681]
res: copy [ ] 
    mix: func [str /local i][
    	if 1 = i: length? str [append res copy head str exit]
    	loop i [
    		append str str/1
    		mix next remove str
    	]
    ]
MaxV
11-Mar-2013
[1682x4]
Just use math:
a: copy []

mix: func [ myword /local n t] [
	n:  length? myword
	t: 1
	loop n [ 
		t: n * t 
		n: n - 1
		]	
	while [(length? a) < t] [
		append a random myword	
		unique a
	
		]
	a	
	]
mix "test"

editor a
I think that it's quicker, since you don't mess with series altering, 
insted you just create mixed words enough to reach the maximum available 
permutations.
For short words...
:-P
NickA
11-Mar-2013
[1686x2]
Thank you guys.  Steve, that's much quicker.  There's no way that 
succeeds without the exponential increase in evaluation, with each 
added character?  I was hoping there might be some magic to learn...
Steve, that code doesn't appear to create all the possible anagrams.
Steeve
11-Mar-2013
[1688x2]
for instance ?
/me pouring a glass of whisky
NickA
11-Mar-2013
[1690x2]
REBOL [title: "Anagram List"]


a:[]m: func[s p][repeat i length? s[append a rejoin[p k: s/:i r: 
head remove at copy s i]m r join p k]]m ask""""editor unique a probe 
length? a


a:[]m: func[s /local i][if 1 = i: length? s[append a copy head s 
exit]loop i[append s s/1 m next remove s]]m ask""editor a probe length? 
a

halt
Mine is the first one, yours is the second.
Steeve
11-Mar-2013
[1692]
can you give a test case where mine is faling ?
NickA
11-Mar-2013
[1693]
Try each line above.  Mine gives 325 anagrams for "asdfg".  Yours 
is much faster, but only results in 120 anagrams for the same input 
string.
Steeve
11-Mar-2013
[1694]
For a 5 letters word, the number of combinations should be 5! (factorial 
5) which gives 120.
NickA
11-Mar-2013
[1695x3]
never mind - stupid me.  didn't count the unique results in mine.
<-- bows low, and walks away :)
I still have the same question though - is there any way to evaluate 
this without the exponential increase in loop counts?
Ladislav
11-Mar-2013
[1698x2]
Nick, it would be actually nice if it was just "exponential growth". 
But the number of permutaions of N elements is N! (N factorial), 
which grows faster than the exponential function.
typo: "permutations"
NickA
11-Mar-2013
[1700]
So there's no way of reducing this problem beyond N! ?