Page 1 of 1

Posted: Thu Jul 04, 2002 4:18 pm
by BackupUser
Restored from previous forum. Originally posted by willinyork.

hi there. if for example I have an alphabet code (like you did when you were a child!) such as A (in the real alphabet) = E in your code, B=P, C=J, D=T etc - how do you do a replacestring() inorder to corretly "translate" one code to the other (or vice versa)? I do a normal placestring as above, but obviously it will replace them in sequence (so sometimes letters get changed twice, and the end string is incorrect). any advice is welcomed! thanks!

Posted: Thu Jul 04, 2002 4:36 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

You could do something like this maybe?

Code: Select all

Global alpha.s,key.s
alpha=" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  key=" QWERTYUIOPLKJHGFDSAZXCVBNM"
   
Procedure.s code(text.s)
  new.s=""
  For tmp=1 To Len(text)
    cur$=Mid(UCase(text),tmp,1)
    pos1=FindString(alpha,cur$,1)
    char$=Mid(key,pos1,1)
    new+char$
  Next
  ProcedureReturn new
EndProcedure
 
Procedure.s decode(text.s)
  new.s=""
  For tmp=1 To Len(text)
    cur$=Mid(UCase(text),tmp,1)
    pos1=FindString(key,cur$,1)
    char$=Mid(alpha,pos1,1)
    new+char$
  Next
  ProcedureReturn new
EndProcedure
 
 
codetext$=code("This is a test")
decodetext$=decode(codetext$)
 
MessageRequester("",codetext$+Chr(10)+decodetext$,0)