我想将日期时间转换为 6 位数字,然后将其转换回准确的日期时间。这个有加密方法吗?

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?

这是我想要做的 (1) 将日期时间转换为 6 位数字;(2) 将 6 位数字转换为输入日期时间。有什么建议吗?

下面是我为完全相同的目的而准备的使用 gtk(在 linux 上)的 python 脚本。如果您有兴趣,我可以将其转换为 C,或者您可以尝试这样做...... 为了尝试它,输入日期 YYMMDDHHmmss 然后点击转换按钮,...非常方便 !!

唯一,我不得不用数字和字母!!!!!

#!/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 ()