SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old June 8th, 2004, 10:59 AM
MeggarK MeggarK is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 MeggarK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
replacing text

I'm in the middle of writing a script that encrypts text. the way it works is it converts the text to binary and then changes the 1s to 0s and the 0s to 1s and converts it back to text again giving an encrypted version of the text. I can get the binary encoding/decoding to work but the bit i'm having trouble with is changing the 1s to 0s and the 0s to 1s. Any help on this would be greatly appreciated.

Thanks,

-MarK

Reply With Quote
  #2  
Old June 8th, 2004, 11:22 AM
Diet-Coke Diet-Coke is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 Diet-Coke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I would not reccomend encrypting text that way. What I would reccomend is to use a matrix. You use the pattern

1 = a
2 = b
3 = c
4 = d
.
.
.
27 = A

etc... what ever you want.... then you take the message such as

Hello

now convert it into the numbers

34 5 12 12 15

now put it into a matrix like so

[34, 5, 12]
[12, 15, 0]

now you need a control matrix like so

[1, 4, 5]
[5, 4, 1]
[4, 5, 1]

now to encrypt it multiply the two matrix like so and you get

[108, 220, 192]
[87 , 108, 75 ]


so the encrypted messege is: 108 220 192 87 108 75

now to decrypt the message you must put it back into a matrix

[108, 220, 192]
[87 , 108, 75 ]

then to decrypt it you must multiply it by the control matrix's recipricl or inverse like so and you get

[34, 5, 12]
[12, 15, 0]

so your message is now back to: 34 5 12 12 15 0

now go to your key what ever it may be... mine is up top and put the numbers with the letters

34 = H
5 = e
12 = l
12 = l
15 = o
0 = space (unless at end means nothing)

so then you get: Hello

vola.

-Coke

Reply With Quote
  #3  
Old June 8th, 2004, 11:25 AM
MeggarK MeggarK is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 MeggarK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yea, i've used that before, but this is just really a mess about i'd still like to be able to try getting my method to work. thanks for that though

Reply With Quote
  #4  
Old June 8th, 2004, 11:32 AM
Diet-Coke Diet-Coke is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 Diet-Coke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well I can't help you with out any code.

-Coke

Reply With Quote
  #5  
Old June 8th, 2004, 03:44 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Iterate over your string. For each numeric character, add to a second string the abs() of that value minus one. This pushes ones back to zeroes and zeroes to abs(-1), which is 1. Some sample code:

PHP Code:
<?php
                                                                                                                                                   
$newstr
="";
$str="1 0 1 0 1 0";
print 
"\n" $str "\n";
                                                                                                                                                   
$count=strlen($str);
                                                                                                                                                   
for(
$i=0$i<$count$i++){
    
$num=substr($str,$i,1);
    if(
is_numeric($num)){
        
$newstr .= abs($num-1);
    }
    else{
        
$newstr .= $num;
    }
}
print 
$newstr "\n";
                                                                                                                                                   
?>
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #6  
Old June 8th, 2004, 03:58 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Another option, of course, is to convert all ones to twos, then all zeroes to ones, then all twos to zeroes using any of the various string replacement functions. It'd be interesting to see which approach is faster.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > replacing text


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway