// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 08/10/2012 8:47:44
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   EncriptarDesencriptar.java

package project;

import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;

// Referenced classes of package project:
//            AccederADatos

public class EncriptarDesencriptar
{

    public EncriptarDesencriptar()
    {
    }

    public static String encriptar(String cadenaEncriptar)
    {
        if(AccederADatos.leer("h.encriptar").compareToIgnoreCase("S\355") == 0)
        {
            cadenaEncriptada = "";
            for(int x = 0; x < cadenaEncriptar.length(); x++)
            {
                caracterEncriptado = cadenaEncriptar.charAt(x);
                cadenaEncriptada = cadenaEncriptada + formatter.format(caracterEncriptado);
            }

        } else
        {
            cadenaEncriptada = cadenaEncriptar;
        }
        return cadenaEncriptada;
    }

    public static String desencriptar(String cadenaDesencriptar)
    {
        if(AccederADatos.leer("h.encriptar").compareToIgnoreCase("S\355") == 0)
        {
            if(cadenaDesencriptar == null)
                cadenaDesencriptar = "";
            else
            if(cadenaDesencriptar.length() < 4)
                cadenaDesencriptar = "";
            cadenaDesencriptada = "";
            for(int x = 0; x < cadenaDesencriptar.length(); x++)
                try
                {
                    caracterEncriptado = Integer.parseInt(cadenaDesencriptar.substring(x, x + 4));
                    cadenaDesencriptada = cadenaDesencriptada + (char)caracterEncriptado;
                    x += 3;
                }
                catch(Exception ex)
                {
                    ex.printStackTrace();
                }

        } else
        {
            cadenaDesencriptada = cadenaDesencriptar;
        }
        return cadenaDesencriptada;
    }

    public static String getStringFromInputStream(InputStream is)
    {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try
        {
            byte buffer[] = new byte[10240];
            int r = 0;
            do
            {
                r = is.read(buffer, 0, 10240);
                if(r > 0)
                    bos.write(buffer, 0, r);
            } while(r > -1);
            bos.flush();
            bos.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return bos.toString();
    }

    public static InputStream getInputStreamFromString(String decodificado)
    {
        ByteArrayInputStream bis = new ByteArrayInputStream(decodificado.getBytes());
        return bis;
    }

    private static String cadenaEncriptada = "";
    private static String cadenaDesencriptada = "";
    private static int caracterEncriptado = 0;
    private static DecimalFormat formatter = new DecimalFormat("0000");

}