Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Prościutki skrypcik hashujący
_Mateo
post
Post #1





Grupa: Zarejestrowani
Postów: 189
Pomógł: 0
Dołączył: 4.03.2005
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


Witam!

Tak mnie coś naszło postanowienie stworzenia jakiejś banalnej funkcji hashującej. Nie wiem na ile mi to wyszło, ale działa.

Oto skrypt:

  1. <?php
  2.  
  3. function mha01 ( $string ) {
  4.  
  5. //czyszczenie ciągu z niedozwolonych znakow
  6.  
  7. $string = trim($string);
  8. $string = strip_tags($string);
  9.  
  10. $count = strlen($string);
  11.  
  12. //zamiana znakow z lancucha na liczby
  13.  
  14. $string = str_replace('A','6408', $string);
  15. $string = str_replace('a','7191', $string);
  16. $string = str_replace('B','2983', $string);
  17. $string = str_replace('b','5330', $string);
  18. $string = str_replace('C','450', $string);
  19. $string = str_replace('c','3367', $string);
  20. $string = str_replace('D','9241', $string);
  21. $string = str_replace('d','8137', $string);
  22. $string = str_replace('E','4472', $string);
  23. $string = str_replace('e','7413', $string);
  24. $string = str_replace('F','3449', $string);
  25. $string = str_replace('f','7408', $string);
  26. $string = str_replace('G','3163', $string);
  27. $string = str_replace('g','269', $string);
  28. $string = str_replace('H','7793', $string);
  29. $string = str_replace('h','1582', $string);
  30. $string = str_replace('I','6208', $string);
  31. $string = str_replace('i','7870', $string);
  32. $string = str_replace('J','9462', $string);
  33. $string = str_replace('j','4095', $string);
  34. $string = str_replace('K','8297', $string);
  35. $string = str_replace('k','1155', $string);
  36. $string = str_replace('L','643', $string);
  37. $string = str_replace('l','3386', $string);
  38. $string = str_replace('M','9116', $string);
  39. $string = str_replace('m','6061', $string);
  40. $string = str_replace('N','8522', $string);
  41. $string = str_replace('n','2891', $string);
  42. $string = str_replace('O','3353', $string);
  43. $string = str_replace('o','3526', $string);
  44. $string = str_replace('P','5289', $string);
  45. $string = str_replace('p','1049', $string);
  46. $string = str_replace('Q','696', $string);
  47. $string = str_replace('q','9486', $string);
  48. $string = str_replace('R','8129', $string);
  49. $string = str_replace('r','1297', $string);
  50. $string = str_replace('S','5831', $string);
  51. $string = str_replace('s','4880', $string);
  52. $string = str_replace('T','9231', $string);
  53. $string = str_replace('t','2072', $string);
  54. $string = str_replace('U','8447', $string);
  55. $string = str_replace('u','5646', $string);
  56. $string = str_replace('V','5783', $string);
  57. $string = str_replace('v','6812', $string);
  58. $string = str_replace('W','3231', $string);
  59. $string = str_replace('w','2720', $string);
  60. $string = str_replace('X','9971', $string);
  61. $string = str_replace('x','3955', $string);
  62. $string = str_replace('Y','9870', $string);
  63. $string = str_replace('y','2040', $string);
  64. $string = str_replace('Z','8984', $string);
  65. $string = str_replace('z','6937', $string);
  66. $string = str_replace('!','5722', $string);
  67. $string = str_replace('@','5617', $string);
  68. $string = str_replace('-','2361', $string);
  69. $string = str_replace('_','1954', $string);
  70. $string = str_replace('1','2215', $string);
  71. $string = str_replace('2','5432', $string);
  72. $string = str_replace('3','4542', $string);
  73. $string = str_replace('4','9644', $string);
  74. $string = str_replace('5','5408', $string);
  75. $string = str_replace('6','4638', $string);
  76. $string = str_replace('7','0145', $string);
  77. $string = str_replace('8','6775', $string);
  78. $string = str_replace('9','2496', $string);
  79. $string = str_replace('0','9535', $string);
  80.  
  81.  
  82. for($i=1; $i<=strlen($string); $i++) {
  83. $output .= $string{$i}*$string{$i+1};
  84. }
  85. $output = round($output/$count);
  86.  
  87. //czyszczenie zmiennej $string
  88.  
  89. $string = null;
  90.  
  91. //obcięcie łańcucha do 12 znakow
  92.  
  93. if(strlen($output)>12) $output=substr($output, 0, 12);
  94.  
  95. //zwrocenie zahashowanego lancucha
  96.  
  97. $output = trim($output);
  98. $output = strip_tags($output);
  99. return $output;
  100.  
  101. }
  102.  
  103. ?>

Oceńcie, ciekaw jestem czy cos takiego może wogole obsługiwać hasła, np w jakimś prostym skrycie z administracją bez użycia znanych algorytmów hashujących.

Pozdrawiam, Mateo.


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 17)
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


Ale po co "czyscisz $stirnga:
  1. <?php
  2. //czyszczenie ciągu z niedozwolonych znakow
  3.  
  4. $string = trim($string);
  5. $string = strip_tags($string);
  6. ?>

A jak mam w hasle "<"?


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
_Mateo
post
Post #3





Grupa: Zarejestrowani
Postów: 189
Pomógł: 0
Dołączył: 4.03.2005
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


Generalnie zakładałem, że nie można do hasła dać takich znaków, ale poprawie.


--------------------
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


md5 czy inne nic nie zakladaja tylko hashuja to co im podasz, a format hasla kontroluj gdzie indziej.


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
mike
post
Post #5





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

Ostrzeżenie: (0%)
-----


Spodziewałem się po kimś kto ma status Developera osoby, która zna manuala.
A tak jeden wielki LOL laugh.gif
Poczytaj sobie dokładniej: str_replace()
Go to the top of the page
+Quote Post
SongoQ
post
Post #6





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Cytat
Spodziewałem się po kimś kto ma status Developera osoby, która zna manuala.

NuLL juz kiedys pisal ze Developerem sa osoby ktore chca wiec sie nie dziw sad.gif


--------------------
Go to the top of the page
+Quote Post
Adiasz
post
Post #7





Grupa: Zarejestrowani
Postów: 155
Pomógł: 0
Dołączył: 28.02.2004

Ostrzeżenie: (0%)
-----


Wogule to po kiego brac sie za pisanie czegos co juz zostalo zaimplementowane w php - np md5? Bo przeciez i tak ani to nie bedzie dzialalo szybciej ani nawet tak samo dobrze.
Go to the top of the page
+Quote Post
SongoQ
post
Post #8





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Cytat
Bo przeciez i tak ani to nie bedzie dzialalo szybciej ani nawet tak samo dobrze.

Dokladnie tak samo mysle. Ale zawsze mozna napisac przynajmniej ktos skrytykuje i zostanie to autorowi w pamieci.


--------------------
Go to the top of the page
+Quote Post
Vengeance
post
Post #9





Grupa: Zarejestrowani
Postów: 657
Pomógł: 2
Dołączył: 15.08.2003
Skąd: Łódź

Ostrzeżenie: (0%)
-----


_Mateo: jeśli już... nie łatwiej jest zrobić for() w którym każdy kolejny znak zamieniasz na jego odpowiedni numer ASCII i przemnazasz wszystkie przez siebie? Proces także nieodwracalny... a ile kodu mniej ;p


--------------------
Go to the top of the page
+Quote Post
sobstel
post
Post #10





Grupa: Zarejestrowani
Postów: 853
Pomógł: 25
Dołączył: 27.08.2003
Skąd: Katowice

Ostrzeżenie: (0%)
-----


co czytam artykul o bezpieczenstwie gdzie poruszona jest troche kryptografia, to wszedzie piszą, zeby korzystac z istniejących rozwiazan, a nie tworzyc wlasnych funkcji kodujacych czy hashujacych, a tymczasem wielu próbuje byc madrzejszych od poteznego grona profesjonalnie zajmujacych sie kryptografią. i moje pytanie @_MAteo jaki jest cel tej twojej funkcji hashujacej? bo na pewno nie zabezpieczenie hasel...

Cytat(SongoQ)
NuLL juz kiedys pisal ze Developerem sa osoby ktore chca wiec sie nie dziw


a czym w ogole zajmuje sie developer php.pl?

Ten post edytował sopel 18.12.2005, 01:23:44


--------------------
"If debugging is the process of removing bugs, then programming must be the process of putting them in..."
sobstel.org
Go to the top of the page
+Quote Post
NuLL
post
Post #11





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

Ostrzeżenie: (0%)
-----


[OT]EOT dot dev.php.pl - developerzy php.pl to grupa obecnie lekko niespojna - po nowym roku zostana zmienione zasady jak funkcjonuje dev i kto w nim jest - wszystkie bedzie jasne i przejrzyste[/OT]


--------------------
Javascript, Coffeescript, Node.js, Mongo, CouchDb, chmury, workery & inne bajery - zycie jest zbyt krotkie aby miec nudna prace :)
Go to the top of the page
+Quote Post
SongoQ
post
Post #12





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Nie chce byc zlosliwy ale troche mnie to smieszy, bo jak php.pl bedzie mialo takie funkcje hashujace to daleko nie zajedzie tongue.gif


--------------------
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #13





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


SongoQ: nie generalizuj. NuLL prosil o EOT. Bo zaraz wroci temat Thota tongue.gif


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
vieri_pl
post
Post #14





Grupa: Zarejestrowani
Postów: 406
Pomógł: 9
Dołączył: 24.07.2005
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Po kiego marnowałeś czas na pisanie funkcji hashującej jak mamy md5 base64 i wiele innych ...
Go to the top of the page
+Quote Post
nospor
post
Post #15





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat(vieri_pl @ 2005-12-18 14:10:15)
Po kiego marnowałeś czas na pisanie funkcji hashującej jak mamy md5 base64 i wiele innych ...

Jesli jeszcze raz ktos sie zapyta po co to bylo pisane skoro jest md5, posypią sie warny. Czytac caly topic do jasnej ciasnej. Juz oto pytano milion razy!

pozatym base64 jest procesem odwracalnym


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
vieri_pl
post
Post #16





Grupa: Zarejestrowani
Postów: 406
Pomógł: 9
Dołączył: 24.07.2005
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Fakt pomyliłem się z base64, ....


edytnołem i veri_pl i alka. Nie wciągajmy mojej rodziny w tematy, które nie mają z tym żadnego związku. ktos cos ma do mnie, to na PW
---
nospor
Go to the top of the page
+Quote Post
_Mateo
post
Post #17





Grupa: Zarejestrowani
Postów: 189
Pomógł: 0
Dołączył: 4.03.2005
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


Wiecie co...

Macie totalną racje smile.gif nie wiem co mi odbiło biggrin.gif
tak czy inaczej wracam do pisania "normalnych" rzeczy smile.gif

Ale dzieki smile.gif Faktycznie mi to pozostanie na dłuuggoo w pamięci smile.gif

Pozdrawiam.


--------------------
Go to the top of the page
+Quote Post
hwao
post
Post #18


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




Ciekawy pomysl, ale kompletnie nie optymalny...
Tez sobie cos takiego napisze.

Ps status developera dotyczy nie tylko programistow ale tez redaktorow, grafikow itp, wiec nie widze powodow do podniety.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 05:32