|
You last visited: Today at 09:07
Advertisement
"Verschlüsselung" in PHP
Discussion on "Verschlüsselung" in PHP within the Coding Snippets forum part of the Coding Releases category.
01/21/2014, 23:41
|
#1
|
elite*gold: 25
Join Date: Sep 2011
Posts: 5,537
Received Thanks: 1,266
|
"Verschlüsselung" in PHP
Hey Leute,
ich habe aus Langeweile mal eine Klasse geschrieben mit der sich einfach Texte verschlüsseln lassen.
Es ist nichts Großes, der Algo dahinter ist auch nichts besonderes.
Aber es ist mal ein unterschied zu den ganzen anderen die man sonst so sieht
PHP Code:
<?php class pCrypt { private $key; public function encrypt($string, $key = ''){ $this->calculateKey($key); $temp = ''; for($i = 0; $i < strlen($string); $i++){ if($i == 0){ $temp .= (ord($string[$i]) + (int)$this->key); }else{ $temp .= '|' . (ord($string[$i]) + (int)$this->key); } } return base64_encode($temp); } public function decrypt($string, $key){ $this->calculateKey($key); $temp = base64_decode($string); $temp = explode('|', $temp); $new = ''; foreach($temp as $item){ $new .= chr(($item - $this->key)); } return $new; } private function calculateKey($key){ $newKey = ''; for($i = 0; $i < strlen($key); $i++){ $newKey += ord($key[$i]); } $this->key = $newKey; } }
Beispiel:
PHP Code:
$crypt = new pCrypt(); $crypted = $crypt->encrypt('Encrypt me', 'mykey'); $plain = $crypt->decrypt($crypted, 'mykey'); echo 'Crypted: ' . $crypted . '<br>'; echo 'Plain: ' . $plain;
Gruß,
Padrio
|
|
|
01/22/2014, 16:15
|
#2
|
elite*gold: 40
Join Date: Mar 2013
Posts: 1,394
Received Thanks: 778
|
Gefällt mir sehr Danke dir
|
|
|
01/23/2014, 11:01
|
#3
|
elite*gold: 0
Join Date: Jan 2010
Posts: 13,150
Received Thanks: 3,207
|
Quote:
NzY2fDY5MHw3NjZ8NjkwfDc2Nnw2OTB8NzY2fDY5MHw3NjZ8Nj kwfDc2Nnw2OTB8NzY2fDY5MHw3NjZ8NjkwfDc2Nnw2OTB8NzY2 fDY5MHw3NjZ8NjkwfDc2Nnw2OTB8NzY2fDY5MHw3NjZ8NjkwfD c2Nnw2OTB8NzY2fDY5MHw3NjZ8NjkwfDc2Nnw2OTB8NzY2fDY5 MHw3NjZ8NjkwfDc2Nnw2OTB8NzY2fDY5MHw3NjZ8NjkwfDc2Nn w2OTB8NzY2fDY5MHw3NjZ8NjkwfDc2Nnw2OTB8NzY2fDY5MA==
|
n bisschen langer encrypt aber schön einfach gehaltene Funktion.
|
|
|
01/23/2014, 18:32
|
#4
|
elite*gold: 25
Join Date: Sep 2011
Posts: 5,537
Received Thanks: 1,266
|
Quote:
Originally Posted by Ravenstorm
n bisschen langer encrypt aber schön einfach gehaltene Funktion.
|
Ich bastel nachher noch einmal ein wenig dran vielleicht lässt sich da noch ein wenig was machen.
|
|
|
01/28/2014, 19:18
|
#5
|
elite*gold: 0
Join Date: May 2010
Posts: 1,380
Received Thanks: 570
|
Sehr schön. Danke Padrio.
|
|
|
04/04/2014, 20:09
|
#6
|
elite*gold: 0
Join Date: Feb 2014
Posts: 4
Received Thanks: 3
|
Einfaches base64 ....
Schade .... hätte an deine Stelle dann doch eher Rot-13 gewählt.
Ist nicht so weit verbreitet wie base.
Dennoch nicht schlecht programmiert.
|
|
|
04/05/2014, 00:04
|
#7
|
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
|
Quote:
Originally Posted by .tux
Einfaches base64 ....
Schade .... hätte an deine Stelle dann doch eher Rot-13 gewählt.
Ist nicht so weit verbreitet wie base.
Dennoch nicht schlecht programmiert.
|
ich hätte ja Rot-26 gewählt. bietet doppelte sicherheit
|
|
|
04/21/2014, 01:45
|
#8
|
elite*gold: 25
Join Date: Feb 2014
Posts: 110
Received Thanks: 62
|
base64 ehrlich ?
|
|
|
04/21/2014, 04:50
|
#9
|
elite*gold: 25
Join Date: Sep 2011
Posts: 5,537
Received Thanks: 1,266
|
Quote:
Originally Posted by .Milo'
base64 ehrlich ?
|
Jup
|
|
|
04/23/2014, 14:59
|
#10
|
elite*gold: 0
Join Date: Apr 2014
Posts: 9
Received Thanks: 2
|
Gefällt mir gut
Hier mal eine alte wo ich noch auf dem Rechner gefunden habe (nicht von mir, aber auch nützlich):
PHP Code:
<?php /** Class for encryption and decryption of the text. This is a simple class which returns the numeric encryption of the text. **It can be further optimised to give better encryption output. **Saji Nair **/ class Encryption { var $key; var $text; function Encryption() { $this->key="mi clave de encripcion"; } /**Function to encrypt the text using the key. ** Returns numeric values for each character concatinated togather. **Saji Nair **/ function encrypt() { $lenText=strlen($this->text); $lenKey=strlen($this->key); $str=""; $j=0; for($i=0;$i<$lenText;$i++,$j++) { if($j==$lenKey) { $j=0; } $val=(ord($this->text[$i])*2)+ord($this->key[$j]); $str.=$val; } return $str; } /**Function to encrypt the text using the key. ** Returns the text from the encrypted numeric value. **Saji Nair **/ function decrypt() { // $this->text=explode("##",$this->text); $temp=$this->text; $temptext=array(); $templen=strlen($temp); for($i=0,$j=0;$i<$templen;$i=$i+3,$j++) { $temptext[$j]=substr($this->text,$i,3); } $lenText=count($temptext); $lenKey=strlen($this->key); $str=""; for($i=0,$j=0;$i<$lenText;$i++,$j++) { if($j==$lenKey) { $j=0; } $val=$temptext[$i]-ord($this->key[$j]); $val=$val/2; $str.=chr($val); } return $str; } } /* $objCls=new Encryption(); $objCls->text="145"; $objCls->text=$objCls->encrypt(); echo $objCls->text; echo $objCls->decrypt(); */ ?>
|
|
|
06/04/2015, 22:17
|
#11
|
elite*gold: 1
Join Date: Aug 2014
Posts: 410
Received Thanks: 54
|
Sowas habe ich überall gesucht, danke dir.
|
|
|
All times are GMT +2. The time now is 09:07.
|
|