# Path: beeswarm/shared/vnc/des.py
# class RFBDes(pyDes.des):
#     def setKey(self, key):
#         """RFB protocol for authentication requires client to encrypt
#            challenge sent by server with password using DES method. However,
#            bits in each byte of the password are put in reverse order before
#            using it as encryption key."""
#         newkey = []
#         for ki in range(len(key)):
#             bsrc = ord(key[ki])
#             btgt = 0
#             for i in range(8):
#                 if bsrc & (1 << i):
#                     btgt |= 1 << 7 - i
#             newkey.append(chr(btgt))
#         super(RFBDes, self).setKey(newkey)


from beeswarm.shared.vnc.des import RFBDes
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Aniket Panse <contact@aniketpanse.in> grants Johnny Vestergaard <jkv@unixcluster.dk>
# a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
# copyright license to reproduce, prepare derivative works of, publicly
# display, publicly perform, sublicense, relicense, and distribute [the] Contributions
# and such derivative works.




class VNCDecoder(object):
    def __init__(self, challenge, response, passwd_list):
        self.challenge = challenge
        self.response = response
        self.passwd_list = passwd_list

    def decode(self):
        for password in self.passwd_list:
            password = password.strip('\n')
            key = (password + '\0' * 8)[:8]
            encryptor = RFBDes(key)

# Path: beeswarm/shared/vnc/des.py
# class RFBDes(pyDes.des):
#     def setKey(self, key):
#         """RFB protocol for authentication requires client to encrypt
#            challenge sent by server with password using DES method. However,
#            bits in each byte of the password are put in reverse order before
#            using it as encryption key."""
#         newkey = []
#         for ki in range(len(key)):
#             bsrc = ord(key[ki])
#             btgt = 0
#             for i in range(8):
#                 if bsrc & (1 << i):
#                     btgt |= 1 << 7 - i
#             newkey.append(chr(btgt))
#         super(RFBDes, self).setKey(newkey)


# Path: beeswarm/shared/vnc/decoder.py
from beeswarm.shared.vnc.des import RFBDes

# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Aniket Panse <contact@aniketpanse.in> grants Johnny Vestergaard <jkv@unixcluster.dk>
# a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
# copyright license to reproduce, prepare derivative works of, publicly
# display, publicly perform, sublicense, relicense, and distribute [the] Contributions
# and such derivative works.




class VNCDecoder(object):
    def __init__(self, challenge, response, passwd_list):
        self.challenge = challenge
        self.response = response
        self.passwd_list = passwd_list

    def decode(self):
        for password in self.passwd_list:
            password = password.strip('\n')
            key = (password + '\0' * 8)[:8]
            encryptor = RFBDes(key)

            resp = encryptor.encrypt(self.challenge)