New topic: 

Strange lag in function

<http://forums.realsoftware.com/viewtopic.php?t=45671>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        Bodevinaat          Post subject: Strange lag in functionPosted: 
Mon Oct 22, 2012 7:26 am                         
Joined: Tue Aug 28, 2012 3:52 am
Posts: 10                Hi,

I have this fairly simple encryption function:
Function Encrypt(plainText as String, aKey as String) as String
  dim aLetter, cipherText as String
  dim i,j,n as Integer
  j = len(aKey)
  n = 1
  for i = 1 to len(clearText)
  aLetter =Chr( asc(mid(clearText,i,1)) + (asc(mid(aKey,n,1))))
  cipherText = cipherText + aLetter
  n = n+ 1
  if n>j then
  n= 1
  end if
  next
  return cipherText



The Decrypt function is exact the same, only it substracts the Ascii values

Function Decrypt(cipherText as String, aKey as String) as String
  dim aLetter, clearText as String
  dim i,j,n as Integer
  j = len(aKey)
  n = 1
  for i = 1 to len(cipherText)
  aLetter =Chr( asc(mid(cipherText,i,1)) - (asc(mid(aKey,n,1))))
  clearText = clearText + aLetter
  n = n+ 1
  if n>j then
  n= 1
  end if
  next
  return clearText


Question is:
Encrypting of 1K of text takes on average 4 to 6 seconds, while decrypting is 
done in split second. I've run this for 10 times so there is no caching or 
similar involved... What creates the time difference?

Run on MacBook Air (SSD), Mountain Lion.   
                             Top                harriew          Post subject: 
Re: Strange lag in functionPosted: Mon Oct 22, 2012 10:25 am                    
     
Joined: Fri Dec 01, 2006 3:09 pm
Posts: 609
Location: Tennessee, USA                One question. In the Encrypt function 
you have the argument "plainText As String" being passed in; but, the code is 
then referring to clearText, something not defined within the function. Could 
this be the problem?   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to