Revision: 2089d0c057
Author: Nightgunner5
Date: Sun Nov 8 14:41:52 2009
Log: Encrypt UI mockup is ready.
http://code.google.com/p/shacrypt/source/detail?r=2089d0c057
Revision: 5d8a048f15
Author: Nightgunner5
Date: Sun Nov 8 16:35:39 2009
Log: Encrypt works fully now.
http://code.google.com/p/shacrypt/source/detail?r=5d8a048f15
==============================================================================
Revision: 2089d0c057
Author: Nightgunner5
Date: Sun Nov 8 14:41:52 2009
Log: Encrypt UI mockup is ready.
http://code.google.com/p/shacrypt/source/detail?r=2089d0c057
Modified:
/Makefile
/glade.c
/shacrypt.glade
=======================================
--- /Makefile Sun Nov 8 07:11:27 2009
+++ /Makefile Sun Nov 8 14:41:52 2009
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
objects=shacrypt.o third-party/sha1.o third-party/sha2.o
third-party/md5c.o third-party/cubehash.o third-party/whirlpool.o
-secondaryobjects=commandline.o shacrypt shacrypt.exe tests.o tests
tests.exe
+secondaryobjects=commandline.o shacrypt shacrypt.exe glade.o shacrypt-gtk
shacrypt-gtk.exe tests.o tests tests.exe
ifndef CFLAGS
CFLAGS=-O2 -Wall -g
@@ -28,6 +28,9 @@
build: commandline.o $(objects)
$(CC) $(CFLAGS) -o shacrypt commandline.o $(objects)
+build-gtk: glade.o $(objects)
+ $(CC) $(CFLAGS) -o shacrypt-gtk glade.o $(objects) `pkg-config --cflags
--libs gtk+-2.0 gmodule-2.0 gthread-2.0`
+
# Hash algorithms
third-party/sha1.o: third-party/sha1.h
third-party/sha2.o: third-party/sha2.h
@@ -40,6 +43,10 @@
shacrypt.h: third-party/sha1.h third-party/sha2.h third-party/md5.h
third-party/cubehash.h third-party/nessie.h
commandline.o: shacrypt.h
tests.o: third-party/sha1.h shacrypt.h
+glade.o: shacrypt.h
+ # This is a horrible, hackish way to do this, but at least it gets the
job done.
+ $(CC) $(CFLAGS) -c -o glade.o glade.c `pkg-config --cflags gtk+-2.0
gmodule-2.0 gthread-2.0`
+
install: build
cp -t $(DESTDIR) shacrypt
@@ -52,4 +59,4 @@
clean:
rm -f $(objects) $(secondaryobjects)
-.PHONY: build install test check clean
+.PHONY: build install test check clean glade.o
=======================================
--- /glade.c Sun Nov 8 08:59:49 2009
+++ /glade.c Sun Nov 8 14:41:52 2009
@@ -1,19 +1,185 @@
-/*
- * Compile me with:
- * gcc -o shacrypt-glade glade.c $(pkg-config --cflags --libs gtk+-2.0
gmodule-2.0)
+/**
+ * SHACrypt graphical user interface
+ *
+ * SHACrypt - Encrypt files using cryptographic hash functions
+ * Copyright (C) 2009 LlamaSlayers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (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/>.
+ *
+ * @since 1.2.1
+ * @version 1.2.1
*/
#include <gtk/gtk.h>
#include <stdio.h>
-G_MODULE_EXPORT void encrypt_button_pressed( GtkWidget* button, gpointer
data ) {
- printf( "W00T!\n%s\n", gtk_widget_get_name( button ) );
+GtkBuilder* builder;
+
+/* Encryption */
+G_MODULE_EXPORT void button_pressed_encrypt( GtkWidget* button, gpointer
data ) {
+ GtkWidget* step1;
+ step1 = GTK_WIDGET( gtk_builder_get_object( builder, "encrypt_step1" )
);
+
+ gtk_widget_show( step1 );
+}
+
+G_MODULE_EXPORT void encrypt_step1_cancel( GtkWidget* button, gpointer
data ) {
+ GtkWidget* step1;
+ step1 = GTK_WIDGET( gtk_builder_get_object( builder, "encrypt_step1" )
);
+
+ gtk_widget_hide( step1 );
+}
+
+G_MODULE_EXPORT void encrypt_step1_ok( GtkWidget* button, gpointer data ) {
+ GtkWidget* step1;
+ GtkWidget* step2;
+ step1 = GTK_WIDGET( gtk_builder_get_object( builder, "encrypt_step1" )
);
+ step2 = GTK_WIDGET( gtk_builder_get_object( builder, "encrypt_step2" )
);
+
+ gtk_widget_hide( step1 );
+ gtk_widget_show( step2 );
+}
+
+/* Password scoring method adapted from
+ * http://www.geekwisdom.com/js/passwordmeter.js
+ */
+G_MODULE_EXPORT void encrypt_step2_passchange( GtkWidget* button, gpointer
data ) {
+ GtkProgressBar* meter;
+ meter = (GtkProgressBar*)GTK_WIDGET( gtk_builder_get_object(
builder, "progressbar_e2_pass_strength" ) );
+
+ int score = 0,
+ lower = 0,
+ upper = 0,
+ num = 0,
+ symb = 0,
+ len, i;
+ const char* pass = gtk_entry_get_text( (GtkEntry*)button );
+
+ len = gtk_entry_get_text_length( (GtkEntry*)button );
+
+ if ( len == 0 ) {
+ gtk_progress_bar_set_fraction( meter, 0.0 );
+ gtk_progress_bar_set_text( meter, "Enter a password." );
+ return;
+
+ }
+
+ // Total length
+ if ( len > 15 ) {
+ score += 18;
+ } else if ( len > 7 ) {
+ score += 12;
+ } else if ( len > 4 ) {
+ score += 6;
+ } else {
+ score += 3;
+ }
+
+ for ( i = 0; i < len; i++ ) {
+ if ( pass[i] >= 'a' && pass[i] <= 'z' )
+ lower++;
+ else if ( pass[i] >= 'A' && pass[i] <= 'Z' )
+ upper++;
+ else if ( pass[i] >= '0' && pass[i] <= '9' )
+ num++;
+ else
+ symb++;
+ }
+
+ // Letters
+ if ( lower || upper )
+ score += 1;
+ if ( lower && upper )
+ score += 2;
+ if ( lower + upper > 1 )
+ score += 2;
+ if ( lower > 1 && upper > 1 )
+ score += 2;
+
+ // Numbers
+ if ( num == 1 )
+ score += 5;
+ if ( num > 1 )
+ score += 7;
+
+ // Symbols
+ if ( symb == 1 )
+ score += 5;
+ if ( symb > 1 )
+ score += 7;
+
+ // Combinations
+ if ( ( upper || lower ) && num )
+ score++;
+ if ( upper && lower )
+ score++;
+ if ( ( upper || lower ) && num && symb )
+ score += 2;
+ if ( upper && lower && num && symb )
+ score += 2;
+
+ gtk_progress_bar_set_fraction( meter, score / 45.0 );
+ if ( score == 45 )
+ gtk_progress_bar_set_text( meter, "Excellent" );
+ else if ( score > 39 )
+ gtk_progress_bar_set_text( meter, "Secure" );
+ else if ( score > 24 )
+ gtk_progress_bar_set_text( meter, "Good" );
+ else if ( score > 9 )
+ gtk_progress_bar_set_text( meter, "Ok" );
+ else
+ gtk_progress_bar_set_text( meter, "Bad" );
+}
+
+G_MODULE_EXPORT void encrypt_step2_ok( GtkWidget* button, gpointer data ) {
+ GtkEntry* pass1;
+ GtkEntry* pass2;
+
+ pass1 = (GtkEntry*)GTK_WIDGET( gtk_builder_get_object(
builder, "field_e2_password1" ) );
+ pass2 = (GtkEntry*)GTK_WIDGET( gtk_builder_get_object(
builder, "field_e2_password2" ) );
+
+ if ( strcmp( gtk_entry_get_text( pass1 ), gtk_entry_get_text( pass2 )
) == 0 ) {
+ GtkWidget* step2;
+ GtkWidget* step3;
+ step2 = GTK_WIDGET( gtk_builder_get_object(
builder, "encrypt_step2" ) );
+ step3 = GTK_WIDGET( gtk_builder_get_object(
builder, "encrypt_step3" ) );
+
+ gtk_widget_hide( step2 );
+ gtk_widget_show( step3 );
+ } else {
+ if ( !g_thread_supported() )
+ g_thread_init( NULL );
+ GThread* enc;
+ enc = g_thread_create( encrypt_step3, NULL, FALSE, NULL );
+ }
+}
+
+G_MODULE_EXPORT void encrypt_step3() {
+
+}
+
+G_MODULE_EXPORT void button_pressed_decrypt( GtkWidget* button, gpointer
data ) {
+
+}
+
+G_MODULE_EXPORT void button_pressed_asymmetric( GtkWidget* button,
gpointer data ) {
+
}
int main( int argc, char** argv ) {
- GtkBuilder *builder;
- GtkWidget *window;
- GError *error = NULL;
+ GtkWidget* window;
+ GError* error = NULL;
gtk_init( &argc, &argv );
@@ -29,8 +195,6 @@
gtk_builder_connect_signals( builder, NULL );
- g_object_unref( G_OBJECT( builder ) );
-
gtk_widget_show( window );
gtk_main();
=======================================
--- /shacrypt.glade Sun Nov 8 08:59:49 2009
+++ /shacrypt.glade Sun Nov 8 14:41:52 2009
@@ -2,152 +2,324 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
- <object class="GtkWindow" id="window1">
- <child>
- <object class="GtkVBox" id="vbox2">
+ <object class="GtkDialog" id="main">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">SHACrypt</property>
+ <property name="resizable">False</property>
+ <property name="type_hint">dialog</property>
+ <property name="has_separator">False</property>
+ <signal name="destroy" handler="gtk_main_quit"/>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
+ <property name="spacing">2</property>
<child>
- <object class="GtkLabel" id="label4">
+ <object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="xpad">5</property>
- <property name="label" translatable="yes">Select a file to
encrypt and a password. The original file will not be modified.</property>
- <property name="justify">center</property>
- <property name="wrap">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="label_welcome">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Welcome to
+SHACrypt 1.2</property>
+ <property name="justify">center</property>
+ <attributes>
+ <attribute name="size" value="25000"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_select_an_action">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Please select an
action.</property>
+ <attributes>
+ <attribute name="size" value="15000"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
- <child>
- <object class="GtkFileChooserWidget" id="filechooserwidget1">
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
+ <property name="homogeneous">True</property>
+ <property name="layout_style">center</property>
+ <child>
+ <object class="GtkButton" id="button_encrypt">
+ <property name="label"
translatable="yes">_Encrypt</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <accelerator key="e" signal="clicked"/>
+ <signal name="clicked" handler="button_pressed_encrypt"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_decrypt">
+ <property name="label"
translatable="yes">_Decrypt</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <accelerator key="d" signal="clicked"/>
+ <signal name="clicked" handler="button_pressed_decrypt"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_asymmetric">
+ <property name="label"
translatable="yes">_Asymmetric</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <accelerator key="a" signal="clicked"/>
+ <signal name="clicked"
handler="button_pressed_asymmetric"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
</packing>
</child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">button_encrypt</action-widget>
+ <action-widget response="0">button_decrypt</action-widget>
+ <action-widget response="0">button_asymmetric</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkFileChooserDialog" id="encrypt_step1_old">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Encrypt a file - Step
1</property>
+ <property name="type_hint">dialog</property>
+ <property name="has_separator">False</property>
+ <signal name="close" handler="encrypt_step1_cancel"/>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
<child>
- <object class="GtkHBox" id="hbox2">
+ <placeholder/>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area2">
<property name="visible">True</property>
+ <property name="layout_style">end</property>
<child>
- <object class="GtkVBox" id="vbox3">
+ <object class="GtkButton" id="button_e1o_cancel">
+ <property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Password for
encryption</property>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="entry1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="visibility">False</property>
- <property name="invisible_char">●</property>
- <property name="truncate_multiline">True</property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="encrypt_step1_cancel"/>
</object>
<packing>
- <property name="padding">10</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkHButtonBox" id="hbuttonbox1">
+ <object class="GtkButton" id="button_e1o_ok">
<property name="visible">True</property>
- <property name="spacing">10</property>
- <property name="layout_style">spread</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="encrypt_step1_ok"/>
<child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
+ <object class="GtkLabel" id="label_e1o_ok">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Ok</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
- <property name="padding">5</property>
- <property name="position">2</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
</child>
+ <action-widgets>
+ <action-widget response="0">button_e1o_cancel</action-widget>
+ <action-widget response="0">button_e1o_ok</action-widget>
+ </action-widgets>
</object>
- <object class="GtkDialog" id="main">
+ <object class="GtkDialog" id="encrypt_step2">
<property name="border_width">5</property>
- <property name="title" translatable="yes">SHACrypt</property>
- <property name="resizable">False</property>
+ <property name="title" translatable="yes">Encrypt a file (Step 2 of
3)</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
- <signal name="destroy" handler="gtk_main_quit"/>
+ <signal name="close" handler="encrypt_step2_cancel"/>
<child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox1">
+ <object class="GtkVBox" id="dialog-vbox3">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
+ <property name="can_focus">True</property>
<child>
- <object class="GtkLabel" id="label_welcome">
+ <object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
- <property name="label" translatable="yes">Welcome to
-SHACrypt 1.2</property>
- <property name="justify">center</property>
- <attributes>
- <attribute name="size" value="25000"/>
- </attributes>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <child>
+ <object class="GtkEntry" id="field_e2_password1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="visibility">False</property>
+ <property name="invisible_char">●</property>
+ <property name="invisible_char_set">True</property>
+ <signal name="changed"
handler="encrypt_step2_passchange"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_e2_password2">
+ <property name="visible">True</property>
+ <property name="xpad">5</property>
+ <property name="ypad">5</property>
+ <property name="label"
translatable="yes">(again)</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="field_e2_password2">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="visibility">False</property>
+ <property name="invisible_char">●</property>
+ <property name="invisible_char_set">True</property>
+ <signal name="changed"
handler="encrypt_step2_passchange"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_e2_password1">
+ <property name="visible">True</property>
+ <property name="xpad">5</property>
+ <property name="ypad">5</property>
+ <property name="label"
translatable="yes">Password</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkProgressBar"
id="progressbar_e2_pass_strength">
+ <property name="visible">True</property>
+ <property name="show_text">True</property>
+ <property name="text" translatable="yes">Enter a
password</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label_e2_basic">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Basic</property>
</object>
<packing>
- <property name="position">0</property>
+ <property name="tab_fill">False</property>
</packing>
</child>
<child>
- <object class="GtkLabel" id="label_select_an_action">
+ <object class="GtkLabel" id="label_e2_comingsoon">
<property name="visible">True</property>
- <property name="label" translatable="yes">Please select an
action.</property>
- <attributes>
- <attribute name="size" value="15000"/>
- </attributes>
+ <property name="label" translatable="yes">Coming
soon!</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
+ <child type="tab">
+ <object class="GtkLabel" id="label_e2_advanced">
+ <property name="visible">True</property>
+ <property name="label"
translatable="yes">Advanced</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area1">
+ <object class="GtkHButtonBox" id="dialog-action_area3">
<property name="visible">True</property>
- <property name="homogeneous">True</property>
- <property name="layout_style">center</property>
+ <property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="button_encrypt">
- <property name="label"
translatable="yes">_Encrypt</property>
+ <object class="GtkButton" id="button_e2_cancel">
+ <property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_underline">True</property>
- <signal name="clicked" handler="encrypt_button_pressed"/>
+ <signal name="clicked" handler="encrypt_step2_cancel"/>
</object>
<packing>
<property name="expand">False</property>
@@ -156,12 +328,20 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button_decrypt">
- <property name="label"
translatable="yes">_Decrypt</property>
+ <object class="GtkButton" id="button_e2_ok">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_underline">True</property>
+ <signal name="clicked" handler="encrypt_step2_ok"/>
+ <child>
+ <object class="GtkLabel" id="label_e2_ok">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Ok</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -169,20 +349,95 @@
<property name="position">1</property>
</packing>
</child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">button_e2_cancel</action-widget>
+ <action-widget response="0">button_e2_ok</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkDialog" id="encrypt_step1">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Encrypt a file (Step 1 of
3)</property>
+ <property name="default_width">500</property>
+ <property name="default_height">400</property>
+ <property name="type_hint">dialog</property>
+ <property name="has_separator">False</property>
+ <signal name="close" handler="encrypt_step1_cancel"/>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox4">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkFileChooserWidget" id="file_e1_select">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="preview_widget_active">False</property>
+ <signal name="file_activated" handler="encrypt_step1_ok"/>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_e1_description">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Select a file to
encrypt.</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">15</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area4">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="button_asymmetric">
- <property name="label"
translatable="yes">_Asymmetric</property>
+ <object class="GtkButton" id="button_e1_cancel">
+ <property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_underline">True</property>
+ <signal name="clicked" handler="encrypt_step1_cancel"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">2</property>
+ <property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkButton" id="button_e1_ok">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="encrypt_step1_ok"/>
+ <child>
+ <object class="GtkLabel" id="label_e1_ok">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Ok</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -193,9 +448,39 @@
</object>
</child>
<action-widgets>
- <action-widget response="0">button_encrypt</action-widget>
- <action-widget response="0">button_decrypt</action-widget>
- <action-widget response="0">button_asymmetric</action-widget>
+ <action-widget response="0">button_e1_cancel</action-widget>
+ <action-widget response="0">button_e1_ok</action-widget>
</action-widgets>
+ </object>
+ <object class="GtkWindow" id="encrypt_step3">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Encrypt a file (Step 3 of
3)</property>
+ <property name="type_hint">dialog</property>
+ <property name="deletable">False</property>
+ <child>
+ <object class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkProgressBar" id="progressbar_e3_progress">
+ <property name="visible">True</property>
+ <property name="show_text">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_e3_description">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">label</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
</object>
</interface>
==============================================================================
Revision: 5d8a048f15
Author: Nightgunner5
Date: Sun Nov 8 16:35:39 2009
Log: Encrypt works fully now.
http://code.google.com/p/shacrypt/source/detail?r=5d8a048f15
Modified:
/glade.c
/shacrypt.c
/shacrypt.glade
/shacrypt.h
=======================================
--- /glade.c Sun Nov 8 14:41:52 2009
+++ /glade.c Sun Nov 8 16:35:39 2009
@@ -23,6 +23,10 @@
#include <gtk/gtk.h>
#include <stdio.h>
+#include <string.h>
+#include "shacrypt.h"
+
+static const char identifier[3] = "\xA7\x09\xC3";
GtkBuilder* builder;
@@ -141,6 +145,81 @@
else
gtk_progress_bar_set_text( meter, "Bad" );
}
+
+G_MODULE_EXPORT void encrypt_step3() {
+ GtkWindow* step3;
+ GtkEntry* pass;
+ GtkFileChooser* file;
+ GtkProgressBar* progress;
+
+ step3 = (GtkWindow*)GTK_WIDGET( gtk_builder_get_object(
builder, "encrypt_step3" ) );
+ pass = (GtkEntry*)GTK_WIDGET( gtk_builder_get_object(
builder, "field_e2_password1" ) );
+ file = (GtkFileChooser*)GTK_WIDGET( gtk_builder_get_object(
builder, "file_e1_select" ) );
+ progress = (GtkProgressBar*)GTK_WIDGET( gtk_builder_get_object(
builder, "progressbar_e3_progress" ) );
+
+ gtk_progress_bar_set_text( progress, NULL );
+ gtk_window_set_deletable( step3, FALSE );
+
+ FILE* f;
+ FILE* o;
+ unsigned long i, n,
+ size;
+ SHACrypt_Context s;
+ unsigned char algos = '\x01';
+ static char fbuf[256] = {0},
+ obuf[256] = {0},
+ tmp[1024] = {0};
+ char* filename;
+
+ filename = gtk_file_chooser_get_filename( file );
+
+ f = fopen( filename, "rb" );
+
+ sprintf( tmp, "%s.shacrypt", filename );
+
+ i = 0;
+ while ( fopen( tmp, "rb" ) != NULL ) {
+ i++;
+ sprintf( tmp, "%s_%lud.shacrypt", filename, i );
+ }
+
+ o = fopen( tmp, "wb" );
+
+ n = SHACrypt_GetLength( algos );
+ for ( i = 0; i < n; i++ )
+ fbuf[i] = g_random_int_range( 0, 255 );
+
+ SHACrypt_Init( &s, (char*)gtk_entry_get_text( pass ),
gtk_entry_get_text_length( pass ), algos, fbuf, n );
+
+ fwrite( identifier, 1, 3, o ); // Identifier
+ fwrite( "\2\0", 1, 2, o ); // Format version
+ fputc( (unsigned char)(n - 1), o ); // Random seed length
+ fwrite( fbuf, 1, n, o ); // Random seed
+ fputc( algos, o ); // Hash alogithms used
+
+ fseek( f, 0, SEEK_END );
+ size = ftell( f );
+ fseek( f, 0, SEEK_SET );
+
+ i = 0;
+
+ /* Do the actual encryption */
+ while ( ( n = fread( fbuf, 1, 256, f ) ) > 0 ) {
+ i += n;
+
+ gtk_progress_bar_set_fraction( progress, (double)i / size );
+
+ SHACrypt_Process( &s, fbuf, obuf, n );
+
+ fwrite( obuf, 1, n, o );
+ }
+
+ fclose( f );
+ fclose( o );
+
+ gtk_progress_bar_set_text( progress, "Done!" );
+ gtk_window_set_deletable( step3, TRUE );
+}
G_MODULE_EXPORT void encrypt_step2_ok( GtkWidget* button, gpointer data ) {
GtkEntry* pass1;
@@ -157,17 +236,12 @@
gtk_widget_hide( step2 );
gtk_widget_show( step3 );
- } else {
- if ( !g_thread_supported() )
- g_thread_init( NULL );
+
GThread* enc;
enc = g_thread_create( encrypt_step3, NULL, FALSE, NULL );
+ } else {
}
}
-
-G_MODULE_EXPORT void encrypt_step3() {
-
-}
G_MODULE_EXPORT void button_pressed_decrypt( GtkWidget* button, gpointer
data ) {
@@ -183,6 +257,9 @@
gtk_init( &argc, &argv );
+ if ( !g_thread_supported() )
+ g_thread_init( NULL );
+
builder = gtk_builder_new();
if( !gtk_builder_add_from_file( builder, "shacrypt.glade", &error ) ) {
@@ -197,6 +274,7 @@
gtk_widget_show( window );
+
gtk_main();
return 0;
=======================================
--- /shacrypt.c Sat Nov 7 09:37:17 2009
+++ /shacrypt.c Sun Nov 8 16:35:39 2009
@@ -107,7 +107,7 @@
return 1;
}
-int _SHACrypt_GetLength( unsigned char algos ) {
+int SHACrypt_GetLength( unsigned char algos ) {
if ( algos & '\xD0' )
return 64;
if ( algos & '\x08' )
@@ -124,7 +124,7 @@
}
int SHACrypt_GetRand( unsigned char algos, char* rand ) {
- int len = _SHACrypt_GetLength( algos );
+ int len = SHACrypt_GetLength( algos );
return SHACrypt_GenRand( rand, len ) ? -len : len;
}
=======================================
--- /shacrypt.glade Sun Nov 8 14:41:52 2009
+++ /shacrypt.glade Sun Nov 8 16:35:39 2009
@@ -117,7 +117,7 @@
<action-widget response="0">button_asymmetric</action-widget>
</action-widgets>
</object>
- <object class="GtkFileChooserDialog" id="encrypt_step1_old">
+ <!--<object class="GtkFileChooserDialog" id="encrypt_step1_old">
<property name="border_width">5</property>
<property name="title" translatable="yes">Encrypt a file - Step
1</property>
<property name="type_hint">dialog</property>
@@ -184,10 +184,101 @@
<action-widget response="0">button_e1o_cancel</action-widget>
<action-widget response="0">button_e1o_ok</action-widget>
</action-widgets>
+ </object>-->
+ <object class="GtkDialog" id="encrypt_step1">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Encrypt a file (Step 1 of
3)</property>
+ <property name="modal">True</property>
+ <property name="default_width">500</property>
+ <property name="default_height">400</property>
+ <property name="type_hint">dialog</property>
+ <property name="has_separator">False</property>
+ <signal name="close" handler="encrypt_step1_cancel"/>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox4">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkFileChooserWidget" id="file_e1_select">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="preview_widget_active">False</property>
+ <signal name="file_activated" handler="encrypt_step1_ok"/>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_e1_description">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Select a file to
encrypt.</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">15</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area4">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button_e1_cancel">
+ <property name="label" translatable="yes">Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="encrypt_step1_cancel"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_e1_ok">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="encrypt_step1_ok"/>
+ <child>
+ <object class="GtkLabel" id="label_e1_ok">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Ok</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">button_e1_cancel</action-widget>
+ <action-widget response="0">button_e1_ok</action-widget>
+ </action-widgets>
</object>
<object class="GtkDialog" id="encrypt_step2">
<property name="border_width">5</property>
<property name="title" translatable="yes">Encrypt a file (Step 2 of
3)</property>
+ <property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
<signal name="close" handler="encrypt_step2_cancel"/>
@@ -332,6 +423,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <accelerator key="Return" signal="clicked"/>
<signal name="clicked" handler="encrypt_step2_ok"/>
<child>
<object class="GtkLabel" id="label_e2_ok">
@@ -363,100 +455,13 @@
<action-widget response="0">button_e2_ok</action-widget>
</action-widgets>
</object>
- <object class="GtkDialog" id="encrypt_step1">
- <property name="border_width">5</property>
- <property name="title" translatable="yes">Encrypt a file (Step 1 of
3)</property>
- <property name="default_width">500</property>
- <property name="default_height">400</property>
- <property name="type_hint">dialog</property>
- <property name="has_separator">False</property>
- <signal name="close" handler="encrypt_step1_cancel"/>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox4">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkFileChooserWidget" id="file_e1_select">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="preview_widget_active">False</property>
- <signal name="file_activated" handler="encrypt_step1_ok"/>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label_e1_description">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Select a file to
encrypt.</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="padding">15</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area4">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="button_e1_cancel">
- <property name="label" translatable="yes">Cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <signal name="clicked" handler="encrypt_step1_cancel"/>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button_e1_ok">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <signal name="clicked" handler="encrypt_step1_ok"/>
- <child>
- <object class="GtkLabel" id="label_e1_ok">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Ok</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="0">button_e1_cancel</action-widget>
- <action-widget response="0">button_e1_ok</action-widget>
- </action-widgets>
- </object>
<object class="GtkWindow" id="encrypt_step3">
<property name="border_width">5</property>
<property name="title" translatable="yes">Encrypt a file (Step 3 of
3)</property>
+ <property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="deletable">False</property>
+ <signal name="delete_event" handler="gtk_widget_hide_on_delete"/>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
@@ -474,7 +479,7 @@
<child>
<object class="GtkLabel" id="label_e3_description">
<property name="visible">True</property>
- <property name="label" translatable="yes">label</property>
+ <property name="label" translatable="yes">Your file is now
being encrypted with the password you specified. A copy has been created,
so the original file will not be modified.</property>
</object>
<packing>
<property name="position">1</property>
=======================================
--- /shacrypt.h Sat Nov 7 09:37:17 2009
+++ /shacrypt.h Sun Nov 8 16:35:39 2009
@@ -76,4 +76,5 @@
void SHACrypt_Init( SHACrypt_Context* ctx, unsigned char* password,
unsigned int passlen,
unsigned char algos, unsigned char* rand, unsigned
char randlen );
void SHACrypt_Process( SHACrypt_Context* ctx, char* in, char* out,
unsigned int len );
+int SHACrypt_GetLength( unsigned char algos );
#endif