Okey, me picó esa curiosidad :P Muchas gracias strup! Un saludo
Nota: Disculpar por marear tanto en el tema del reto :/
♠♥♣♦
de nada hombre, para eso estamosBaal_30 escribió:Okey, me picó esa curiosidad :P Muchas gracias strup! Un saludo
Nota: Disculpar por marear tanto en el tema del reto :/
from random import random
class hippiescantreadme:
def __init__(self, sText, sKey, nIter):
self.iv = int(random()*100) #aleatorio, o puedes indicarlo como fijo
self.sText = sText
self.sKey = sKey
self.nIter = nIter
def xEncode(self):
data = []
if type(self.sText) is str:
self.sText = [ord(x) for x in self.sText]
for x in self.sText:
prev = self.iv ^ x
data.append(prev)
self.iv = prev
data = zip(data, self.sKey)
data = [x*ord(z)**self.nIter for x,z in data]
for i in range(1, self.nIter+1):
data = [(x*self.nIter*i) for x in data]
return data
#para decode es necesario saber cual es el IV inicial
def xDecode(self):
for i in range(1, self.nIter+1):
self.sText = [(x/self.nIter/i) for x in self.sText]
data = zip(self.sText, self.sKey)
decoded = ""
for i in data:
prev = i[0]/ord(i[1])**self.nIter
decoded += chr(prev ^ self.iv)
self.iv = prev
return decoded
LOOOL piensas igual que yo?, yo tambien randomice numeros pero de 32 digitos para generar cifrados distintos, de hecho yo termine ya el mio anoche solo me falta retocarlo un poco en los resultados y estara listo para la presentacion ,de hecho el mio retorna el iv en una dupla que contendra tambien el cifrado, (cifrado,IV), saludos maquinasanko escribió:vale, entonces lo dejo asi y me olvido ya del tema:
from random import random class hippiescantreadme: def __init__(self, sText, sKey, nIter): self.iv = int(random()*100) #aleatorio, o puedes indicarlo como fijo self.sText = sText self.sKey = sKey self.nIter = nIter def xEncode(self): data = [] if type(self.sText) is str: self.sText = [ord(x) for x in self.sText] for x in self.sText: prev = self.iv ^ x data.append(prev) self.iv = prev data = zip(data, self.sKey) data = [x*ord(z)**self.nIter for x,z in data] for i in range(1, self.nIter+1): data = [(x*self.nIter*i) for x in data] return data #para decode es necesario saber cual es el IV inicial def xDecode(self): for i in range(1, self.nIter+1): self.sText = [(x/self.nIter/i) for x in self.sText] data = zip(self.sText, self.sKey) decoded = "" for i in data: prev = i[0]/ord(i[1])**self.nIter decoded += chr(prev ^ self.iv) self.iv = prev return decoded
El cifrado variará gracias al IV, soltando cada vez un resultado diferente, pero el decode será siempre el mismo, gracias a operar con el iv:
Código: Seleccionar todo
Cadena Cifrada: lz{'kl?l'Jpmyhkv
Salida: Test de Cifrado
Func _Cifrar($sString, $sClave)
Local $sIV = Random(10, 99, 1)
Local $sAscIV = ChrW($sIV)
Local $sArrayString = StringToASCIIArray($sString)
Local $sOperacion, $sReturn
For $i = 0 to UBound($sArrayString) - 1
$sOperacion = $sArrayString[$i] + $sIV
$sIV += AscW(BinaryToString($sClave, 2)) - BitXOR(StringLen($sClave), $sIV)
$sReturn = $sReturn & $sOperacion & '.'
Next
Local $sRecorte = StringTrimRight($sReturn, 1)
Local $sFiltrado = StringSplit($sRecorte, '.', 1)
Local $sConvert = StringFromASCIIArray($sFiltrado)
Local $sCifrado = StringMid($sConvert, 1, StringLen($sConvert) / 2) & $sAscIV & StringMid($sConvert, StringLen($sConvert) / 2)
Return $sCifrado
EndFunc
Func _Descifrar($sString, $sClave)
Local $sPrimeraMitad = StringMid($sString, 1,(StringLen($sString) / 2) - 1)
Local $sSegundaMitad = StringMid($sString, (StringLen($sString) / 2) + 2)
Local $sRecortando = StringTrimLeft($sString, StringLen($sPrimeraMitad))
Local $sRecortando2 = StringTrimRight($sRecortando, StringLen($sSegundaMitad))
$sString = $sPrimeraMitad & $sSegundaMitad
Local $sIV = AscW($sRecortando2)
Local $sArrayString = StringToASCIIArray($sString)
Local $sOperacion, $sReturn
For $i = 1 to UBound($sArrayString) - 1
$sOperacion = $sArrayString[$i] - $sIV
$sIV += AscW(BinaryToString($sClave, 2)) - BitXOR(StringLen($sClave), $sIV)
$sReturn = $sReturn & $sOperacion & '.'
Next
Local $sFiltrado = StringSplit($sReturn, '.', 1)
Local $sASCIItoString = StringFromASCIIArray($sFiltrado)
Local $sDescifrado = StringTrimLeft($sASCIItoString, 1)
Return $sDescifrado
EndFunc
Como nadie se animo a hacer la GUI, aquí dejo la mía por si quieren testear.Código: Seleccionar todo
module KRI32(kri,dKri) where
{-
Cifrado: Kri32
Autor: Strup
Descripción: Cifra una cadena en KRI32 y la Descifra.(K: key statica, R: random, I: iv de 32 bytes).
Cifrado con key statica con uso de un randomizador de vectores de inicializacion de 32 bytes
Data: 29/05/2014 - 22:49
-}
import System.Random(getStdRandom,randomR)
import Data.Bits(shiftL,shiftR,xor)
import Data.Char(ord,chr)
type ClaveNumerica = Integer
type PasswordText = String
type Desplazamiento = Int
type CifradoAndIV = IO ()
type Descifrado = String
type Cifrado = String
type Texto = String
type IV = Integer
staticKey = map(\(s,t) -> if (read s :: Int) > 99 then (tail s,t) else (s,t)).map(\(x,y) -> (show x,y)).zip [0..] $ ['A'..'Z']++['0'..'9']++"*+-,.<>[]{}'!@#$%&/()=¿?|^`´¶"++['a'..'z']++"_:;®ª·ºÇç ¨¥§¡Ñ~ñØÆ"
kri :: Texto -> PasswordText -> ClaveNumerica -> Desplazamiento -> CifradoAndIV
kri xs ps0 ps1 dl = do
xr <- xXor
let respuesta = (reverse.tapar.show.shiftL(resultado * (fst $ xr)) $ dl,show.snd $ xr)
putStrLn.fst $ respuesta -- Cifrado.
putStrLn.snd $ respuesta -- Vector de inicialización.
where
calculo = (shiftL.fromIntegral.sum.map(ord) $ ps0) 8
to_Integer n = (read n :: Integer)
resultado = calculo * (to_Integer.(++)(show.length $ ps0).concat.mapear $ xs)
mapear = map(\x -> if ord x < 10 then "00"++show (ord x) else if ord x < 100 then '0':show (ord x) else show(ord x))
xXor = do
vecIni <- getStdRandom(randomR(10000000000000000000000000000000,99999999999999999999999999999999))
return (ps1 `shiftL` dl `xor` vecIni,vecIni)
tapar :: String -> String
tapar [] = []
tapar xs = foldr(\(x,z) -> \y -> if x == take 2 xs then [z]++y else y)[]staticKey++tapar (drop 2 xs)
dKri :: Monad m => Cifrado -> PasswordText -> ClaveNumerica -> Desplazamiento -> IV -> m Descifrado
dKri xs ps0 ps1 dl iv = do
return.extraer.drop(length.show.length $ ps0).show.dResultado.reverse $ xs
where
dResultado yx = (toInteger.destapar $ yx) `shiftR` dl `div` dXor `div` dCalculo
dCalculo = (shiftL.fromIntegral.sum.map(ord) $ ps0) 8
toInteger n = read n :: Integer
dXor = ps1 `shiftL` dl `xor` iv
extraer :: String -> String
extraer [] = []
extraer (x:y:z:str) = [chr(read [x,y,z] :: Int)]++extraer str
destapar :: String -> String
destapar [] = []
destapar (s:st) = concat(map(\(x,y) -> if y == s then x else "")staticKey)++destapar st
si te refieres a operacioens matematicas puede ser cualquiera que tenga su contra parte es decir, la contraparte de la multiplicacion es la division y de la suma la resta y del xor es asi mismo como se descifra, solo tienes que pasar el resultado por el valor con el que xoreaste, hay mas, y incluso estas se combinan y demas, yo de hecho incluso desplace bits en las claves y en los resultados para aumentar la ofuscacionBaal_30 escribió:Muy bueno strup :P Vaya, nada nada, me rayé xD
Código: Seleccionar todo
private static String encrypt(String str, String key) {
String ret = "";
byte[] sData = str.getBytes();
byte[] kData = new byte[sData.length];
int kDataCount = 0;
for (int i = 0; i < kData.length; i++) {
if (kDataCount != key.length()) {
kData[i] = (byte) key.charAt(kDataCount);
} else {
kDataCount = 0;
kData[i] = kData[kDataCount];
}
kDataCount++;
}
for (int i = 0; i < sData.length; i++) {
int sum = kData[i];
String sSum = (sum + sData[i]) + "";
if (sSum.length() < 3) {
sSum = "0" + sSum;
}
ret += sSum + "" + (sData[i] + Integer.parseInt(sSum));
}
return ret;
}
private static String decrypt(String str) {
String ret = "";
for (int i = 0; i < str.length(); i = i + 6) {
String s = str.substring(i, i + 6);
ret += (char) (Integer.parseInt(s.substring(3, 6)) - Integer.parseInt(s.substring(0, 3)));
}
return ret;
}
Volver a “Mensajes Entre Nosotros”