Search code examples
c++encryptionencodechecksumcrc

I want to convert date time into 6 digit number, then convert it back into the exact date time. Is there a encryption method to this?


Here are what I want do (1) convert date time to 6digit number ;(2)convert the 6digit number to the input date time. Any suggestion to do this?


Solution

  • The below is a python script that uses gtk (on linux) that I prepared for exactly the same purpose. If you are interested, I can convert it to C, or you can try to do so... In order to try it, input the date as YYMMDDHHmmss then click the convert button, ... very handy !!

    The only thing, I had to use numbers and letters !!!!!

    #!/usr/bin/python
    
    import os
    import sys
    import pygtk
    pygtk.require ( '2.0' )
    import gtk
    
    def to_digit(a):
        if (a < 10) and (a >= 0):
            return chr(48 + a)
        elif (a < 36) and (a > 9):
            return chr(55 + a)
        elif (a < 60) and (a > 35):
            return chr(61 + a)
        else:
            return chr(95)
    #
    
    def to_int(c):
        if (ord(c) < 58) and (ord(c) > 47):
            return ord(c)-48
        elif (ord(c) < 91) and (ord(c) > 64):
            return ord(c)-55
        elif (ord(c) < 123) and (ord(c) > 96):
            return ord(c)-61
    #
    
    def m_call(a):
        st = ''
        if a == 0:
            return '0'
        while a:
            b = a % 100
            a = a / 100
            st = to_digit(b) + st
        return st
    #
    
    def rev_m_call(st):
        cumul = 0
        for i in range(len(st)):
            cumul += to_int(st[i:i+1])*pow(10,2*(len(st)-i-1))
        return cumul
    #
    
    class frmMain:
    
        def run_cmd(self, widget, data=None):
            if data == 'o1':
                self.output_entry.set_text (m_call(int(self.input_entry.get_text())))
            elif data == 'o2':
                self.input_entry.set_text (str(rev_m_call(self.output_entry.get_text())))
            elif data == 'c':
                self.input_entry.set_text ("")
                self.output_entry.set_text ("")
            else:
                pass
    
        def delete_event(self, widget, event, data=None):
            print ("delete event occurred")
            return False
    
        def destroy(self, widget, data=None):
            gtk.main_quit ()
    
        def __init__(self):
    
            self.WIDTH  = 300
            self.HEIGHT = 60
    
            self.window = gtk.Window ( gtk.WINDOW_TOPLEVEL )
            self.window.set_title ( "Give the date to convert to code!!" )
            self.window.set_size_request ( self.WIDTH, self.HEIGHT )
            self.window.set_resizable ( False )
            self.window.connect ( "delete_event", self.delete_event )
            self.window.connect ( "destroy", self.destroy )
            self.window.set_border_width ( 2 )
            vb = gtk.VBox ( False, 0 )
            self.window.add ( vb )
            hb = gtk.HBox ( True, 0 )
            self.input_entry = gtk.Entry ()
            hb.pack_start ( self.input_entry, False, True, 2 )
            self.output_entry = gtk.Entry ()
            hb.pack_start (self.output_entry, False, True, 2 )
            vb.pack_start ( hb, False, True, 2 )
            hb = gtk.HBox ( False, 0 )
            r1 = gtk.Button ( ">======->>" )
            r1.connect ( "clicked", self.run_cmd, 'o1' )
            hb.pack_end ( r1, False, False, 2 )
            r2 = gtk.Button ( "<<-======<" )
            r2.connect ( "clicked", self.run_cmd, 'o2' )
            hb.pack_end ( r2, False, False, 2 )
            clear_button = gtk.Button ( "Clear" )
            clear_button.connect ( "clicked", self.run_cmd, 'c' )
            hb.pack_end ( clear_button, False, False, 2 )
            cancel_button = gtk.Button ( "Cancel" )
            cancel_button.connect ( "clicked", self.destroy )
            hb.pack_end ( cancel_button, False, False, 2 )
            vb.pack_start ( hb, False, True, 2 )
            self.window.show_all ()
    
        def main(self):
            gtk.main()
    
    
    
    if __name__ == "__main__":
        run = frmMain ()
        run.main ()